{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "# encoding=utf-8\n",
    "import os.path as osp\n",
    "import os\n",
    "import copy\n",
    "import matplotlib.pyplot as plt\n",
    "import torch\n",
    "from torch.nn import Linear\n",
    "from sklearn.metrics import average_precision_score, roc_auc_score\n",
    "from torch_geometric.data import TemporalData\n",
    "from torch_geometric.datasets import JODIEDataset\n",
    "from torch_geometric.datasets import ICEWS18\n",
    "from torch_geometric.nn import TGNMemory, TransformerConv\n",
    "import torch.nn as nn\n",
    "import torch.nn.functional as F\n",
    "from torch_geometric.nn.models.tgn import (LastNeighborLoader, IdentityMessage, MeanAggregator,\n",
    "                                           LastAggregator)\n",
    "from torch_geometric import *\n",
    "from torch_geometric.utils import negative_sampling\n",
    "from tqdm import tqdm\n",
    "import networkx as nx\n",
    "import numpy as np\n",
    "import math\n",
    "import copy\n",
    "import re\n",
    "import time\n",
    "import json\n",
    "import pandas as pd\n",
    "from random import choice\n",
    "import gc\n",
    "device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')\n",
    "# device = 'cpu'\n",
    "# msg structure:      [src_node_feature,edge_attr,dst_node_feature]\n",
    "\n",
    "# compute the best partition\n",
    "import datetime\n",
    "# import community as community_louvain\n",
    "\n",
    "import xxhash\n",
    "#  Find the edge index which the edge vector is corresponding to\n",
    "def tensor_find(t,x):\n",
    "    t_np=t.cpu().numpy()\n",
    "    idx=np.argwhere(t_np==x)\n",
    "    return idx[0][0]+1\n",
    "\n",
    "\n",
    "def std(t):\n",
    "    t = np.array(t)\n",
    "    return np.std(t)\n",
    "\n",
    "\n",
    "def var(t):\n",
    "    t = np.array(t)\n",
    "    return np.var(t)\n",
    "\n",
    "\n",
    "def mean(t):\n",
    "    t = np.array(t)\n",
    "    return np.mean(t)\n",
    "\n",
    "def hashgen(l):\n",
    "    \"\"\"Generate a single hash value from a list. @l is a list of\n",
    "    string values, which can be properties of a node/edge. This\n",
    "    function returns a single hashed integer value.\"\"\"\n",
    "    hasher = xxhash.xxh64()\n",
    "    for e in l:\n",
    "        hasher.update(e)\n",
    "    return hasher.intdigest()\n",
    "\n",
    "\n",
    "def cal_pos_edges_loss(link_pred_ratio):\n",
    "    loss=[]\n",
    "    for i in link_pred_ratio:\n",
    "        loss.append(criterion(i,torch.ones(1)))\n",
    "    return torch.tensor(loss)\n",
    "\n",
    "def cal_pos_edges_loss_multiclass(link_pred_ratio,labels):\n",
    "    loss=[] \n",
    "    for i in range(len(link_pred_ratio)):\n",
    "        loss.append(criterion(link_pred_ratio[i].reshape(1,-1),labels[i].reshape(-1)))\n",
    "    return torch.tensor(loss)\n",
    "\n",
    "def cal_pos_edges_loss_autoencoder(decoded,msg):\n",
    "    loss=[] \n",
    "    for i in range(len(decoded)):\n",
    "        loss.append(criterion(decoded[i].reshape(1,-1),msg[i].reshape(-1)))\n",
    "    return torch.tensor(loss)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/javascript": [
       "IPython.notebook.set_autosave_interval(120000)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Autosaving every 120 seconds\n"
     ]
    }
   ],
   "source": [
    "%autosave 120  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "from datetime import datetime, timezone\n",
    "import time\n",
    "import pytz\n",
    "from time import mktime\n",
    "from datetime import datetime\n",
    "import time\n",
    "def ns_time_to_datetime(ns):\n",
    "    \"\"\"\n",
    "    :param ns: int nano timestamp\n",
    "    :return: datetime   format: 2013-10-10 23:40:00.000000000\n",
    "    \"\"\"\n",
    "    dt = datetime.fromtimestamp(int(ns) // 1000000000)\n",
    "    s = dt.strftime('%Y-%m-%d %H:%M:%S')\n",
    "    s += '.' + str(int(int(ns) % 1000000000)).zfill(9)\n",
    "    return s\n",
    "\n",
    "def ns_time_to_datetime_US(ns):\n",
    "    \"\"\"\n",
    "    :param ns: int nano timestamp\n",
    "    :return: datetime   format: 2013-10-10 23:40:00.000000000\n",
    "    \"\"\"\n",
    "    tz = pytz.timezone('US/Eastern')\n",
    "    dt = pytz.datetime.datetime.fromtimestamp(int(ns) // 1000000000, tz)\n",
    "    s = dt.strftime('%Y-%m-%d %H:%M:%S')\n",
    "    s += '.' + str(int(int(ns) % 1000000000)).zfill(9)\n",
    "    return s\n",
    "\n",
    "def time_to_datetime_US(s):\n",
    "    \"\"\"\n",
    "    :param ns: int nano timestamp\n",
    "    :return: datetime   format: 2013-10-10 23:40:00\n",
    "    \"\"\"\n",
    "    tz = pytz.timezone('US/Eastern')\n",
    "    dt = pytz.datetime.datetime.fromtimestamp(int(s), tz)\n",
    "    s = dt.strftime('%Y-%m-%d %H:%M:%S')\n",
    "\n",
    "    return s\n",
    "\n",
    "def datetime_to_ns_time(date):\n",
    "    \"\"\"\n",
    "    :param date: str   format: %Y-%m-%d %H:%M:%S   e.g. 2013-10-10 23:40:00\n",
    "    :return: nano timestamp\n",
    "    \"\"\"\n",
    "    timeArray = time.strptime(date, \"%Y-%m-%d %H:%M:%S\")\n",
    "    timeStamp = int(time.mktime(timeArray))\n",
    "    timeStamp = timeStamp * 1000000000\n",
    "    return timeStamp\n",
    "\n",
    "def datetime_to_ns_time_US(date):\n",
    "    \"\"\"\n",
    "    :param date: str   format: %Y-%m-%d %H:%M:%S   e.g. 2013-10-10 23:40:00\n",
    "    :return: nano timestamp\n",
    "    \"\"\"\n",
    "    tz = pytz.timezone('US/Eastern')\n",
    "    timeArray = time.strptime(date, \"%Y-%m-%d %H:%M:%S\")\n",
    "    dt = datetime.fromtimestamp(mktime(timeArray))\n",
    "    timestamp = tz.localize(dt)\n",
    "    timestamp = timestamp.timestamp()\n",
    "    timeStamp = timestamp * 1000000000\n",
    "    return int(timeStamp)\n",
    "\n",
    "def datetime_to_timestamp_US(date):\n",
    "    \"\"\"\n",
    "    :param date: str   format: %Y-%m-%d %H:%M:%S   e.g. 2013-10-10 23:40:00\n",
    "    :return: nano timestamp\n",
    "    \"\"\"\n",
    "    tz = pytz.timezone('US/Eastern')\n",
    "    timeArray = time.strptime(date, \"%Y-%m-%d %H:%M:%S\")\n",
    "    dt = datetime.fromtimestamp(mktime(timeArray))\n",
    "    timestamp = tz.localize(dt)\n",
    "    timestamp = timestamp.timestamp()\n",
    "    timeStamp = timestamp\n",
    "    return int(timeStamp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "import psycopg2\n",
    "\n",
    "from psycopg2 import extras as ex\n",
    "connect = psycopg2.connect(database = 'tc_e5_theia_dataset_db',\n",
    "                           host = '/var/run/postgresql/',\n",
    "                           user = 'postgres',\n",
    "                           password = 'postgres',\n",
    "                           port = '5432'\n",
    "                          )\n",
    "\n",
    "cur = connect.cursor()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "graph_5_8=torch.load(\"./train_graphs/graph_5_8.TemporalData.simple\").to(device=device)\n",
    "graph_5_9=torch.load(\"./train_graphs/graph_5_9.TemporalData.simple\").to(device=device)\n",
    "\n",
    "\n",
    "train_data=graph_5_8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Constructing the map for nodeid to msg\n",
    "sql=\"select * from node2id ORDER BY index_id;\"\n",
    "cur.execute(sql)\n",
    "rows = cur.fetchall()\n",
    "\n",
    "nodeid2msg={}  # nodeid => msg and node hash => nodeid\n",
    "for i in rows:\n",
    "    nodeid2msg[i[0]]=i[-1]\n",
    "    nodeid2msg[i[-1]]={i[1]:i[2]}  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "rel2id={1: 'EVENT_CONNECT',\n",
    " 'EVENT_CONNECT': 1,\n",
    " 2: 'EVENT_EXECUTE',\n",
    " 'EVENT_EXECUTE': 2,\n",
    " 3: 'EVENT_OPEN',\n",
    " 'EVENT_OPEN': 3,\n",
    " 4: 'EVENT_READ',\n",
    " 'EVENT_READ': 4,\n",
    " 5: 'EVENT_RECVFROM',\n",
    " 'EVENT_RECVFROM': 5,\n",
    " 6: 'EVENT_RECVMSG',\n",
    " 'EVENT_RECVMSG': 6,\n",
    " 7: 'EVENT_SENDMSG',\n",
    " 'EVENT_SENDMSG': 7,\n",
    " 8: 'EVENT_SENDTO',\n",
    " 'EVENT_SENDTO': 8,\n",
    " 9: 'EVENT_WRITE',\n",
    " 'EVENT_WRITE': 9}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "# train_data, val_data, test_data = data.train_val_test_split(val_ratio=0.15, test_ratio=0.15)\n",
    "# max_node_num = max(torch.cat([data.dst,data.src]))+1\n",
    "# max_node_num = data.num_nodes+1\n",
    "max_node_num = 967389  # +1\n",
    "# min_dst_idx, max_dst_idx = int(data.dst.min()), int(data.dst.max())\n",
    "min_dst_idx, max_dst_idx = 0, max_node_num\n",
    "neighbor_loader = LastNeighborLoader(max_node_num, size=20, device=device)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "class GraphAttentionEmbedding(torch.nn.Module):\n",
    "    def __init__(self, in_channels, out_channels, msg_dim, time_enc):\n",
    "        super(GraphAttentionEmbedding, self).__init__()\n",
    "        self.time_enc = time_enc\n",
    "        edge_dim = msg_dim + time_enc.out_channels\n",
    "        self.conv = TransformerConv(in_channels, out_channels, heads=8,\n",
    "                                    dropout=0.0, edge_dim=edge_dim)\n",
    "        self.conv2 = TransformerConv(out_channels*8, out_channels,heads=1, concat=False,\n",
    "                             dropout=0.0, edge_dim=edge_dim)\n",
    "\n",
    "    def forward(self, x, last_update, edge_index, t, msg):\n",
    "        last_update.to(device)\n",
    "        x = x.to(device)\n",
    "        t = t.to(device)\n",
    "        rel_t = last_update[edge_index[0]] - t\n",
    "        rel_t_enc = self.time_enc(rel_t.to(x.dtype))\n",
    "        edge_attr = torch.cat([rel_t_enc, msg], dim=-1)\n",
    "        x = F.relu(self.conv(x, edge_index, edge_attr))\n",
    "        x = F.relu(self.conv2(x, edge_index, edge_attr))\n",
    "        return x\n",
    "\n",
    "\n",
    "class LinkPredictor(torch.nn.Module):\n",
    "    def __init__(self, in_channels):\n",
    "        super(LinkPredictor, self).__init__()\n",
    "        self.lin_src = Linear(in_channels, in_channels*2)\n",
    "        self.lin_dst = Linear(in_channels, in_channels*2)\n",
    "        \n",
    "        self.lin_seq = nn.Sequential(\n",
    "            \n",
    "            Linear(in_channels*4, in_channels*8),\n",
    "            torch.nn.Dropout(0.5),\n",
    "            nn.Tanh(),\n",
    "            Linear(in_channels*8, in_channels*2),\n",
    "            torch.nn.Dropout(0.5),\n",
    "            nn.Tanh(),\n",
    "            Linear(in_channels*2, int(in_channels//2)),\n",
    "            torch.nn.Dropout(0.5),\n",
    "            nn.Tanh(),\n",
    "            Linear(int(in_channels//2), train_data.msg.shape[1]-32)                   \n",
    "        )\n",
    "        \n",
    "\n",
    "    def forward(self, z_src, z_dst):\n",
    "        h = torch.cat([self.lin_src(z_src) , self.lin_dst(z_dst)],dim=-1)      \n",
    "         \n",
    "        h = self.lin_seq (h)\n",
    "        \n",
    "        return h\n",
    "\n",
    "memory_dim = 100         # node state\n",
    "time_dim = 100\n",
    "embedding_dim = 200      # edge embedding\n",
    "\n",
    "memory = TGNMemory(\n",
    "    max_node_num,\n",
    "    train_data.msg.size(-1),\n",
    "    memory_dim,\n",
    "    time_dim,\n",
    "    message_module=IdentityMessage(train_data.msg.size(-1), memory_dim, time_dim),\n",
    "    aggregator_module=LastAggregator(),\n",
    ").to(device)\n",
    "\n",
    "gnn = GraphAttentionEmbedding(\n",
    "    in_channels=memory_dim,\n",
    "    out_channels=embedding_dim,\n",
    "    msg_dim=train_data.msg.size(-1),\n",
    "    time_enc=memory.time_enc,\n",
    ").to(device)\n",
    "\n",
    "link_pred = LinkPredictor(in_channels=embedding_dim).to(device)\n",
    "\n",
    "optimizer = torch.optim.Adam(\n",
    "    set(memory.parameters()) | set(gnn.parameters())\n",
    "    | set(link_pred.parameters()), lr=0.00005, eps=1e-08,weight_decay=0.01)\n",
    "\n",
    "\n",
    "# scheduler = torch.optim.lr_scheduler.StepLR(optimizer, step_size=5, gamma=0.1)\n",
    "criterion = nn.CrossEntropyLoss()\n",
    "\n",
    "# Helper vector to map global node indices to local ones.\n",
    "assoc = torch.empty(max_node_num, dtype=torch.long, device=device)\n",
    "\n",
    "saved_nodes=set()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "BATCH=1024\n",
    "def train(train_data):\n",
    "\n",
    "    \n",
    "    memory.train()\n",
    "    gnn.train()\n",
    "    link_pred.train()\n",
    "\n",
    "    memory.reset_state()  # Start with a fresh memory.\n",
    "    neighbor_loader.reset_state()  # Start with an empty graph.\n",
    "    saved_nodes=set()\n",
    "\n",
    "    total_loss = 0\n",
    "    \n",
    "#     print(\"train_before_stage_data:\",train_data)\n",
    "    for batch in train_data.seq_batches(batch_size=BATCH):\n",
    "        optimizer.zero_grad()\n",
    "\n",
    "        src, pos_dst, t, msg = batch.src, batch.dst, batch.t, batch.msg        \n",
    "        \n",
    "        n_id = torch.cat([src, pos_dst]).unique()\n",
    "#         n_id = torch.cat([src, pos_dst, neg_src, neg_dst]).unique()\n",
    "        n_id, edge_index, e_id = neighbor_loader(n_id)\n",
    "        assoc[n_id] = torch.arange(n_id.size(0), device=device)\n",
    "\n",
    "        # Get updated memory of all nodes involved in the computation.\n",
    "        z, last_update = memory(n_id)\n",
    "      \n",
    "        z = gnn(z, last_update, edge_index, train_data.t[e_id], train_data.msg[e_id])\n",
    "        \n",
    "        pos_out = link_pred(z[assoc[src]], z[assoc[pos_dst]])       \n",
    "\n",
    "        y_pred = torch.cat([pos_out], dim=0)\n",
    "        \n",
    "#         y_true = torch.cat([torch.zeros(pos_out.size(0),1),torch.ones(neg_out.size(0),1)], dim=0)\n",
    "        y_true=[]\n",
    "        for m in msg:\n",
    "            l=tensor_find(m[16:-16],1)-1\n",
    "            y_true.append(l)           \n",
    "          \n",
    "        y_true = torch.tensor(y_true).to(device=device)\n",
    "        y_true=y_true.reshape(-1).to(torch.long).to(device=device)\n",
    "        \n",
    "        loss = criterion(y_pred, y_true)\n",
    "        \n",
    "#         loss = criterion(pos_out, torch.ones_like(pos_out))\n",
    "#         loss += criterion(neg_out, torch.zeros_like(neg_out))\n",
    "\n",
    "        # Update memory and neighbor loader with ground-truth state.\n",
    "        memory.update_state(src, pos_dst, t, msg)\n",
    "        neighbor_loader.insert(src, pos_dst)\n",
    "        \n",
    "#         for i in range(len(src)):\n",
    "#             saved_nodes.add(int(src[i]))\n",
    "#             saved_nodes.add(int(pos_dst[i]))\n",
    "\n",
    "        loss.backward()\n",
    "        optimizer.step()\n",
    "        memory.detach()\n",
    "#         print(z.shape)\n",
    "        total_loss += float(loss) * batch.num_events\n",
    "#     print(\"trained_stage_data:\",train_data)\n",
    "    return total_loss / train_data.num_events\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\r",
      "  0%|                                                                                                   | 0/30 [00:00<?, ?it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Epoch: 01, Loss: 0.3370\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\r",
      "  3%|██▉                                                                                     | 1/30 [07:04<3:25:09, 424.48s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Epoch: 01, Loss: 0.1800\n",
      "  Epoch: 02, Loss: 0.2369\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\r",
      "  7%|█████▊                                                                                  | 2/30 [14:06<3:17:24, 423.01s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Epoch: 02, Loss: 0.1668\n",
      "  Epoch: 03, Loss: 0.2535\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\r",
      " 10%|████████▊                                                                               | 3/30 [21:13<3:11:06, 424.68s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Epoch: 03, Loss: 0.1642\n",
      "  Epoch: 04, Loss: 0.2338\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\r",
      " 13%|███████████▋                                                                            | 4/30 [28:17<3:03:54, 424.42s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Epoch: 04, Loss: 0.1638\n",
      "  Epoch: 05, Loss: 0.2395\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\r",
      " 17%|██████████████▋                                                                         | 5/30 [35:20<2:56:44, 424.19s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Epoch: 05, Loss: 0.1595\n",
      "  Epoch: 06, Loss: 0.2486\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\r",
      " 20%|█████████████████▌                                                                      | 6/30 [42:25<2:49:44, 424.36s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Epoch: 06, Loss: 0.1622\n",
      "  Epoch: 07, Loss: 0.2504\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\r",
      " 23%|████████████████████▌                                                                   | 7/30 [49:30<2:42:46, 424.65s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Epoch: 07, Loss: 0.1623\n",
      "  Epoch: 08, Loss: 0.2352\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\r",
      " 27%|███████████████████████▍                                                                | 8/30 [56:36<2:35:48, 424.93s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Epoch: 08, Loss: 0.1592\n",
      "  Epoch: 09, Loss: 0.2272\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\r",
      " 30%|█████████████████████████▊                                                            | 9/30 [1:03:41<2:28:45, 425.02s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Epoch: 09, Loss: 0.1599\n",
      "  Epoch: 10, Loss: 0.2298\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\r",
      " 33%|████████████████████████████▎                                                        | 10/30 [1:10:48<2:21:51, 425.58s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Epoch: 10, Loss: 0.1567\n",
      "  Epoch: 11, Loss: 0.2257\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\r",
      " 37%|███████████████████████████████▏                                                     | 11/30 [1:17:53<2:14:45, 425.54s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Epoch: 11, Loss: 0.1567\n",
      "  Epoch: 12, Loss: 0.2339\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\r",
      " 40%|██████████████████████████████████                                                   | 12/30 [1:24:58<2:07:35, 425.30s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Epoch: 12, Loss: 0.1567\n",
      "  Epoch: 13, Loss: 0.2164\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\r",
      " 43%|████████████████████████████████████▊                                                | 13/30 [1:32:03<2:00:27, 425.15s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Epoch: 13, Loss: 0.1577\n",
      "  Epoch: 14, Loss: 0.2090\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\r",
      " 47%|███████████████████████████████████████▋                                             | 14/30 [1:39:06<1:53:10, 424.44s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Epoch: 14, Loss: 0.1556\n",
      "  Epoch: 15, Loss: 0.2002\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\r",
      " 50%|██████████████████████████████████████████▌                                          | 15/30 [1:46:09<1:45:59, 423.93s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Epoch: 15, Loss: 0.1556\n",
      "  Epoch: 16, Loss: 0.2306\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\r",
      " 53%|█████████████████████████████████████████████▎                                       | 16/30 [1:53:11<1:38:49, 423.53s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Epoch: 16, Loss: 0.1565\n",
      "  Epoch: 17, Loss: 0.2195\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\r",
      " 57%|████████████████████████████████████████████████▏                                    | 17/30 [2:00:14<1:31:42, 423.24s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Epoch: 17, Loss: 0.1553\n",
      "  Epoch: 18, Loss: 0.2022\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\r",
      " 60%|███████████████████████████████████████████████████                                  | 18/30 [2:07:16<1:24:36, 423.01s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Epoch: 18, Loss: 0.1551\n",
      "  Epoch: 19, Loss: 0.1921\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\r",
      " 63%|█████████████████████████████████████████████████████▊                               | 19/30 [2:14:18<1:17:29, 422.70s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Epoch: 19, Loss: 0.1547\n",
      "  Epoch: 20, Loss: 0.2305\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\r",
      " 67%|████████████████████████████████████████████████████████▋                            | 20/30 [2:21:20<1:10:25, 422.59s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Epoch: 20, Loss: 0.1545\n",
      "  Epoch: 21, Loss: 0.2371\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\r",
      " 70%|███████████████████████████████████████████████████████████▍                         | 21/30 [2:28:43<1:04:18, 428.72s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Epoch: 21, Loss: 0.1567\n",
      "  Epoch: 22, Loss: 0.2163\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\r",
      " 73%|███████████████████████████████████████████████████████████████▊                       | 22/30 [2:35:58<57:24, 430.51s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Epoch: 22, Loss: 0.1545\n",
      "  Epoch: 23, Loss: 0.2337\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\r",
      " 77%|██████████████████████████████████████████████████████████████████▋                    | 23/30 [2:43:16<50:29, 432.77s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Epoch: 23, Loss: 0.1557\n",
      "  Epoch: 24, Loss: 0.2277\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\r",
      " 80%|█████████████████████████████████████████████████████████████████████▌                 | 24/30 [2:50:39<43:34, 435.69s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Epoch: 24, Loss: 0.1563\n",
      "  Epoch: 25, Loss: 0.2223\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\r",
      " 83%|████████████████████████████████████████████████████████████████████████▌              | 25/30 [2:58:30<37:11, 446.35s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Epoch: 25, Loss: 0.1550\n",
      "  Epoch: 26, Loss: 0.2135\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\r",
      " 87%|███████████████████████████████████████████████████████████████████████████▍           | 26/30 [3:11:05<35:56, 539.04s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Epoch: 26, Loss: 0.1541\n",
      "  Epoch: 27, Loss: 0.2305\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\r",
      " 90%|██████████████████████████████████████████████████████████████████████████████▎        | 27/30 [3:24:15<30:42, 614.17s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Epoch: 27, Loss: 0.1544\n",
      "  Epoch: 28, Loss: 0.2133\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\r",
      " 93%|█████████████████████████████████████████████████████████████████████████████████▏     | 28/30 [3:36:41<21:47, 653.96s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Epoch: 28, Loss: 0.1549\n",
      "  Epoch: 29, Loss: 0.2005\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\r",
      " 97%|████████████████████████████████████████████████████████████████████████████████████   | 29/30 [3:44:01<09:49, 589.65s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Epoch: 29, Loss: 0.1530\n",
      "  Epoch: 30, Loss: 0.2218\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|███████████████████████████████████████████████████████████████████████████████████████| 30/30 [3:51:28<00:00, 462.96s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Epoch: 30, Loss: 0.1548\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "\n",
    "train_graphs=[graph_5_8,graph_5_9]\n",
    "\n",
    "for epoch in tqdm(range(1, 31)):\n",
    "    for g in train_graphs:\n",
    "        loss = train(g)\n",
    "        print(f'  Epoch: {epoch:02d}, Loss: {loss:.4f}')\n",
    "#     scheduler.step()\n",
    "\n",
    "model=[memory,gnn, link_pred,neighbor_loader]\n",
    "os.system(\"mkdir -p ./models/\")\n",
    "torch.save(model,\"./models/model_saved_share.pt\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "import time \n",
    "\n",
    "@torch.no_grad()\n",
    "def test_day_new(inference_data,path):\n",
    "    if os.path.exists(path):\n",
    "        pass\n",
    "    else:\n",
    "        os.mkdir(path)\n",
    "    \n",
    "    memory.eval()\n",
    "    gnn.eval()\n",
    "    link_pred.eval()\n",
    "    \n",
    "    memory.reset_state()  # Start with a fresh memory. \n",
    "    neighbor_loader.reset_state()  # Start with an empty graph.\n",
    "    \n",
    "    time_with_loss={}\n",
    "    total_loss = 0    \n",
    "    edge_list=[]\n",
    "    \n",
    "    unique_nodes=torch.tensor([]).to(device=device)\n",
    "    total_edges=0\n",
    "\n",
    "\n",
    "    start_time=inference_data.t[0]\n",
    "    event_count=0\n",
    "    \n",
    "    pos_o=[]\n",
    "    \n",
    "    loss_list=[]\n",
    "    \n",
    "\n",
    "    print(\"after merge:\",inference_data)\n",
    "    \n",
    "    # Record the running time to evaluate the performance\n",
    "    start = time.perf_counter()\n",
    "\n",
    "    for batch in inference_data.seq_batches(batch_size=BATCH):\n",
    "        \n",
    "        src, pos_dst, t, msg = batch.src, batch.dst, batch.t, batch.msg\n",
    "        unique_nodes=torch.cat([unique_nodes,src,pos_dst]).unique()\n",
    "        total_edges+=BATCH\n",
    "        \n",
    "       \n",
    "        n_id = torch.cat([src, pos_dst]).unique()       \n",
    "        n_id, edge_index, e_id = neighbor_loader(n_id)\n",
    "        assoc[n_id] = torch.arange(n_id.size(0), device=device)\n",
    "\n",
    "        z, last_update = memory(n_id)\n",
    "        z = gnn(z, last_update, edge_index, inference_data.t[e_id], inference_data.msg[e_id])\n",
    "\n",
    "        pos_out = link_pred(z[assoc[src]], z[assoc[pos_dst]])\n",
    "        \n",
    "        pos_o.append(pos_out)\n",
    "        y_pred = torch.cat([pos_out], dim=0)\n",
    "#         y_true = torch.cat(\n",
    "#             [torch.ones(pos_out.size(0))], dim=0).to(torch.long)     \n",
    "#         y_true=y_true.reshape(-1).to(torch.long)\n",
    "\n",
    "        y_true=[]\n",
    "        for m in msg:\n",
    "            l=tensor_find(m[16:-16],1)-1\n",
    "            y_true.append(l) \n",
    "        y_true = torch.tensor(y_true).to(device=device)\n",
    "        y_true=y_true.reshape(-1).to(torch.long).to(device=device)\n",
    "\n",
    "        # Only consider which edge hasn't been correctly predicted.\n",
    "        # For benign graphs, the behaviors patterns are similar and therefore their losses are small\n",
    "        # For anoamlous behaviors, some behaviors might not be seen before, so the probability of predicting those edges are low. Thus their losses are high.\n",
    "        loss = criterion(y_pred, y_true)\n",
    "\n",
    "        total_loss += float(loss) * batch.num_events\n",
    "     \n",
    "        \n",
    "        # update the edges in the batch to the memory and neighbor_loader\n",
    "        memory.update_state(src, pos_dst, t, msg)\n",
    "        neighbor_loader.insert(src, pos_dst)\n",
    "        \n",
    "        # compute the loss for each edge\n",
    "        each_edge_loss= cal_pos_edges_loss_multiclass(pos_out,y_true)\n",
    "        \n",
    "        for i in range(len(pos_out)):\n",
    "            srcnode=int(src[i])\n",
    "            dstnode=int(pos_dst[i])  \n",
    "            \n",
    "            srcmsg=str(nodeid2msg[srcnode]) \n",
    "            dstmsg=str(nodeid2msg[dstnode])\n",
    "            t_var=int(t[i])\n",
    "            edgeindex=tensor_find(msg[i][16:-16],1)   \n",
    "            edge_type=rel2id[edgeindex]\n",
    "            loss=each_edge_loss[i]    \n",
    "\n",
    "            temp_dic={}\n",
    "            temp_dic['loss']=float(loss)\n",
    "            temp_dic['srcnode']=srcnode\n",
    "            temp_dic['dstnode']=dstnode\n",
    "            temp_dic['srcmsg']=srcmsg\n",
    "            temp_dic['dstmsg']=dstmsg\n",
    "            temp_dic['edge_type']=edge_type\n",
    "            temp_dic['time']=t_var\n",
    "            \n",
    "#             if \"netflow\" in srcmsg or \"netflow\" in dstmsg:\n",
    "#                 temp_dic['loss']=0\n",
    "            edge_list.append(temp_dic)\n",
    "        \n",
    "        event_count+=len(batch.src)\n",
    "        if t[-1]>start_time+60000000000*15:\n",
    "            # Here is a checkpoint, which records all edge losses in the current time window\n",
    "#             loss=total_loss/event_count\n",
    "            time_interval=ns_time_to_datetime_US(start_time)+\"~\"+ns_time_to_datetime_US(t[-1])\n",
    "\n",
    "            end = time.perf_counter()\n",
    "            time_with_loss[time_interval]={'loss':loss,\n",
    "                                \n",
    "                                          'nodes_count':len(unique_nodes),\n",
    "                                          'total_edges':total_edges,\n",
    "                                          'costed_time':(end-start)}\n",
    "            \n",
    "            \n",
    "            log=open(path+\"/\"+time_interval+\".txt\",'w')\n",
    "            \n",
    "            for e in edge_list: \n",
    "#                 temp_key=e['srcmsg']+e['dstmsg']+e['edge_type']\n",
    "#                 if temp_key in train_edge_set:      \n",
    "# #                     e['loss']=(e['loss']-train_edge_set[temp_key]) if e['loss']>=train_edge_set[temp_key] else 0  \n",
    "# #                     e['loss']=abs(e['loss']-train_edge_set[temp_key])\n",
    "                    \n",
    "#                     e['modified']=True\n",
    "#                 else:\n",
    "#                     e['modified']=False\n",
    "                loss+=e['loss']\n",
    "\n",
    "            loss=loss/event_count   \n",
    "            print(f'Time: {time_interval}, Loss: {loss:.4f}, Nodes_count: {len(unique_nodes)}, Cost Time: {(end-start):.2f}s')\n",
    "            edge_list = sorted(edge_list, key=lambda x:x['loss'],reverse=True)   # # Rank the results based on edge loss\n",
    "            for e in edge_list: \n",
    "                log.write(str(e))\n",
    "                log.write(\"\\n\") \n",
    "            event_count=0\n",
    "            total_loss=0\n",
    "            loss=0\n",
    "            start_time=t[-1]\n",
    "            log.close()\n",
    "            edge_list.clear()\n",
    "            \n",
    " \n",
    "    return time_with_loss\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "graph_5_11=torch.load(\"./train_graphs/graph_5_11.TemporalData.simple\").to(device=device)\n",
    "graph_5_14=torch.load(\"./train_graphs/graph_5_14.TemporalData.simple\").to(device=device)\n",
    "graph_5_15=torch.load(\"./train_graphs/graph_5_15.TemporalData.simple\").to(device=device)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "model=torch.load(\"./models/model_saved_emb100_BATCH_1024_LastAggregator_multiclass.pt\")\n",
    "memory,gnn, link_pred,neighbor_loader=model\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "after merge: TemporalData(dst=[9622633], msg=[9622633, 41], src=[9622633], t=[9622633])\n",
      "Time: 2019-05-08 00:00:01.330026026~2019-05-08 00:15:29.528868509, Loss: 0.2533, Nodes_count: 2356, Cost Time: 3.27s\n",
      "Time: 2019-05-08 00:15:29.528868509~2019-05-08 00:34:01.494985889, Loss: 0.1424, Nodes_count: 82297, Cost Time: 16.07s\n",
      "Time: 2019-05-08 00:34:01.494985889~2019-05-08 00:49:53.634712131, Loss: 0.1474, Nodes_count: 96517, Cost Time: 30.03s\n",
      "Time: 2019-05-08 00:49:53.634712131~2019-05-08 01:05:30.922847747, Loss: 0.0515, Nodes_count: 96653, Cost Time: 42.35s\n",
      "Time: 2019-05-08 01:05:30.922847747~2019-05-08 01:20:31.497361112, Loss: 0.2232, Nodes_count: 96737, Cost Time: 45.05s\n",
      "Time: 2019-05-08 01:20:31.497361112~2019-05-08 01:35:41.695160354, Loss: 0.1846, Nodes_count: 96837, Cost Time: 47.96s\n",
      "Time: 2019-05-08 01:35:41.695160354~2019-05-08 01:53:50.594670267, Loss: 0.0746, Nodes_count: 97677, Cost Time: 66.73s\n",
      "Time: 2019-05-08 01:53:50.594670267~2019-05-08 02:09:43.350837131, Loss: 0.2224, Nodes_count: 97794, Cost Time: 70.29s\n",
      "Time: 2019-05-08 02:09:43.350837131~2019-05-08 02:26:01.494039907, Loss: 0.1610, Nodes_count: 98001, Cost Time: 74.54s\n",
      "Time: 2019-05-08 02:26:01.494039907~2019-05-08 02:42:31.494332605, Loss: 0.1390, Nodes_count: 98124, Cost Time: 77.92s\n",
      "Time: 2019-05-08 02:42:31.494332605~2019-05-08 02:58:57.023132578, Loss: 0.1623, Nodes_count: 98414, Cost Time: 81.48s\n",
      "Time: 2019-05-08 02:58:57.023132578~2019-05-08 03:13:57.095448637, Loss: 0.1148, Nodes_count: 98591, Cost Time: 90.29s\n",
      "Time: 2019-05-08 03:13:57.095448637~2019-05-08 03:32:08.466033172, Loss: 0.1687, Nodes_count: 98910, Cost Time: 94.99s\n",
      "Time: 2019-05-08 03:32:08.466033172~2019-05-08 03:48:47.382438643, Loss: 0.1702, Nodes_count: 99001, Cost Time: 98.16s\n",
      "Time: 2019-05-08 03:48:47.382438643~2019-05-08 04:04:46.414529639, Loss: 0.1985, Nodes_count: 99069, Cost Time: 101.31s\n",
      "Time: 2019-05-08 04:04:46.414529639~2019-05-08 04:20:01.518779113, Loss: 0.0796, Nodes_count: 99216, Cost Time: 110.36s\n",
      "Time: 2019-05-08 04:20:01.518779113~2019-05-08 04:35:58.858520828, Loss: 0.1379, Nodes_count: 99285, Cost Time: 112.87s\n",
      "Time: 2019-05-08 04:35:58.858520828~2019-05-08 04:51:14.379786874, Loss: 0.1477, Nodes_count: 99427, Cost Time: 117.50s\n",
      "Time: 2019-05-08 04:51:14.379786874~2019-05-08 05:06:20.739790014, Loss: 0.2338, Nodes_count: 100686, Cost Time: 121.70s\n",
      "Time: 2019-05-08 05:06:20.739790014~2019-05-08 05:21:29.411470192, Loss: 0.0650, Nodes_count: 100989, Cost Time: 130.80s\n",
      "Time: 2019-05-08 05:21:29.411470192~2019-05-08 05:37:31.515609538, Loss: 0.1763, Nodes_count: 101151, Cost Time: 134.90s\n",
      "Time: 2019-05-08 05:37:31.515609538~2019-05-08 05:53:31.497131397, Loss: 0.1679, Nodes_count: 101427, Cost Time: 141.48s\n",
      "Time: 2019-05-08 05:53:31.497131397~2019-05-08 06:10:58.534552244, Loss: 0.0634, Nodes_count: 104732, Cost Time: 149.34s\n",
      "Time: 2019-05-08 06:10:58.534552244~2019-05-08 06:27:01.496508811, Loss: 0.2131, Nodes_count: 104809, Cost Time: 151.90s\n",
      "Time: 2019-05-08 06:27:01.496508811~2019-05-08 06:44:01.510476913, Loss: 0.0528, Nodes_count: 115074, Cost Time: 172.76s\n",
      "Time: 2019-05-08 06:44:01.510476913~2019-05-08 06:59:29.081176105, Loss: 0.1155, Nodes_count: 124443, Cost Time: 185.51s\n",
      "Time: 2019-05-08 06:59:29.081176105~2019-05-08 07:16:21.527799306, Loss: 0.1447, Nodes_count: 124605, Cost Time: 191.58s\n",
      "Time: 2019-05-08 07:16:21.527799306~2019-05-08 07:31:31.498367791, Loss: 0.1337, Nodes_count: 124721, Cost Time: 195.81s\n",
      "Time: 2019-05-08 07:31:31.498367791~2019-05-08 07:47:59.950266127, Loss: 0.2063, Nodes_count: 124931, Cost Time: 198.90s\n",
      "Time: 2019-05-08 07:47:59.950266127~2019-05-08 08:04:24.283283892, Loss: 0.1904, Nodes_count: 126779, Cost Time: 202.79s\n",
      "Time: 2019-05-08 08:04:24.283283892~2019-05-08 08:19:25.079188234, Loss: 0.3909, Nodes_count: 128447, Cost Time: 210.47s\n",
      "Time: 2019-05-08 08:19:25.079188234~2019-05-08 08:35:56.405929191, Loss: 3.9109, Nodes_count: 129797, Cost Time: 235.28s\n",
      "Time: 2019-05-08 08:35:56.405929191~2019-05-08 08:51:31.494691070, Loss: 0.1379, Nodes_count: 130330, Cost Time: 246.35s\n",
      "Time: 2019-05-08 08:51:31.494691070~2019-05-08 09:07:45.182895158, Loss: 0.2134, Nodes_count: 143431, Cost Time: 261.41s\n",
      "Time: 2019-05-08 09:07:45.182895158~2019-05-08 09:23:31.510817939, Loss: 4.2804, Nodes_count: 144348, Cost Time: 279.82s\n",
      "Time: 2019-05-08 09:23:31.510817939~2019-05-08 09:38:32.042400342, Loss: 3.5219, Nodes_count: 144920, Cost Time: 298.32s\n",
      "Time: 2019-05-08 09:38:32.042400342~2019-05-08 09:53:59.985955797, Loss: 2.4017, Nodes_count: 145296, Cost Time: 315.98s\n",
      "Time: 2019-05-08 09:53:59.985955797~2019-05-08 10:09:28.157340956, Loss: 0.2152, Nodes_count: 145645, Cost Time: 327.80s\n",
      "Time: 2019-05-08 10:09:28.157340956~2019-05-08 10:24:33.040435131, Loss: 0.1141, Nodes_count: 146004, Cost Time: 349.54s\n",
      "Time: 2019-05-08 10:24:33.040435131~2019-05-08 10:39:56.645975541, Loss: 0.1889, Nodes_count: 146530, Cost Time: 369.62s\n",
      "Time: 2019-05-08 10:39:56.645975541~2019-05-08 10:54:57.371031778, Loss: 0.1559, Nodes_count: 147237, Cost Time: 390.71s\n",
      "Time: 2019-05-08 10:54:57.371031778~2019-05-08 11:11:40.968208138, Loss: 0.0770, Nodes_count: 147497, Cost Time: 431.13s\n",
      "Time: 2019-05-08 11:11:40.968208138~2019-05-08 11:26:47.315251658, Loss: 0.1466, Nodes_count: 147672, Cost Time: 438.76s\n",
      "Time: 2019-05-08 11:26:47.315251658~2019-05-08 11:44:32.386385923, Loss: 0.1179, Nodes_count: 147949, Cost Time: 452.16s\n",
      "Time: 2019-05-08 11:44:32.386385923~2019-05-08 11:59:56.165297922, Loss: 0.1343, Nodes_count: 148425, Cost Time: 470.21s\n",
      "Time: 2019-05-08 11:59:56.165297922~2019-05-08 12:15:54.940816182, Loss: 0.1535, Nodes_count: 148682, Cost Time: 477.41s\n",
      "Time: 2019-05-08 12:15:54.940816182~2019-05-08 12:31:15.278340529, Loss: 0.1173, Nodes_count: 148905, Cost Time: 490.77s\n",
      "Time: 2019-05-08 12:31:15.278340529~2019-05-08 12:46:31.494879192, Loss: 0.1203, Nodes_count: 149119, Cost Time: 498.76s\n",
      "Time: 2019-05-08 12:46:31.494879192~2019-05-08 13:02:51.596182752, Loss: 0.1577, Nodes_count: 149458, Cost Time: 522.87s\n",
      "Time: 2019-05-08 13:02:51.596182752~2019-05-08 13:18:09.403271887, Loss: 0.1281, Nodes_count: 149781, Cost Time: 552.04s\n",
      "Time: 2019-05-08 13:18:09.403271887~2019-05-08 13:33:49.475905288, Loss: 0.8717, Nodes_count: 150210, Cost Time: 587.62s\n",
      "Time: 2019-05-08 13:33:49.475905288~2019-05-08 13:49:07.975590004, Loss: 0.2814, Nodes_count: 150519, Cost Time: 598.51s\n",
      "Time: 2019-05-08 13:49:07.975590004~2019-05-08 14:04:08.362986281, Loss: 0.1712, Nodes_count: 150920, Cost Time: 621.99s\n",
      "Time: 2019-05-08 14:04:08.362986281~2019-05-08 14:20:38.626291924, Loss: 0.1713, Nodes_count: 151096, Cost Time: 630.64s\n",
      "Time: 2019-05-08 14:20:38.626291924~2019-05-08 14:38:16.822010916, Loss: 0.1691, Nodes_count: 151436, Cost Time: 643.20s\n",
      "Time: 2019-05-08 14:38:16.822010916~2019-05-08 14:53:23.122855676, Loss: 0.9499, Nodes_count: 151782, Cost Time: 660.43s\n",
      "Time: 2019-05-08 14:53:23.122855676~2019-05-08 15:08:42.441638215, Loss: 0.1208, Nodes_count: 152098, Cost Time: 683.41s\n",
      "Time: 2019-05-08 15:08:42.441638215~2019-05-08 15:24:01.898655291, Loss: 0.3268, Nodes_count: 152278, Cost Time: 692.86s\n",
      "Time: 2019-05-08 15:24:01.898655291~2019-05-08 15:39:06.558035649, Loss: 0.1385, Nodes_count: 152525, Cost Time: 702.00s\n",
      "Time: 2019-05-08 15:39:06.558035649~2019-05-08 15:54:07.906775809, Loss: 0.1768, Nodes_count: 153033, Cost Time: 717.83s\n",
      "Time: 2019-05-08 15:54:07.906775809~2019-05-08 16:09:11.911547021, Loss: 0.1124, Nodes_count: 153293, Cost Time: 731.71s\n",
      "Time: 2019-05-08 16:09:11.911547021~2019-05-08 16:24:14.553496865, Loss: 0.1092, Nodes_count: 153511, Cost Time: 744.23s\n",
      "Time: 2019-05-08 16:24:14.553496865~2019-05-08 16:41:01.513629313, Loss: 0.0968, Nodes_count: 153647, Cost Time: 762.19s\n",
      "Time: 2019-05-08 16:41:01.513629313~2019-05-08 16:59:31.493980102, Loss: 0.1948, Nodes_count: 153658, Cost Time: 763.62s\n",
      "Time: 2019-05-08 16:59:31.493980102~2019-05-08 17:18:31.513488653, Loss: 0.1886, Nodes_count: 153667, Cost Time: 764.02s\n",
      "Time: 2019-05-08 17:18:31.513488653~2019-05-08 17:34:01.511886204, Loss: 0.2204, Nodes_count: 153667, Cost Time: 764.29s\n",
      "Time: 2019-05-08 17:34:01.511886204~2019-05-08 17:53:01.523458251, Loss: 0.2285, Nodes_count: 153675, Cost Time: 764.62s\n",
      "Time: 2019-05-08 17:53:01.523458251~2019-05-08 18:10:31.516914310, Loss: 0.1894, Nodes_count: 153681, Cost Time: 764.95s\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Time: 2019-05-08 18:10:31.516914310~2019-05-08 18:28:01.502529875, Loss: 0.2018, Nodes_count: 153690, Cost Time: 765.35s\n",
      "Time: 2019-05-08 18:28:01.502529875~2019-05-08 18:46:31.493999871, Loss: 0.1675, Nodes_count: 153693, Cost Time: 765.80s\n",
      "Time: 2019-05-08 18:46:31.493999871~2019-05-08 19:04:31.510623654, Loss: 0.1925, Nodes_count: 153701, Cost Time: 766.40s\n",
      "Time: 2019-05-08 19:04:31.510623654~2019-05-08 19:23:01.507250100, Loss: 0.1739, Nodes_count: 153710, Cost Time: 766.76s\n",
      "Time: 2019-05-08 19:23:01.507250100~2019-05-08 19:39:31.523720172, Loss: 0.1606, Nodes_count: 153710, Cost Time: 767.11s\n",
      "Time: 2019-05-08 19:39:31.523720172~2019-05-08 19:55:31.512169904, Loss: 0.2018, Nodes_count: 153720, Cost Time: 767.37s\n",
      "Time: 2019-05-08 19:55:31.512169904~2019-05-08 20:14:01.524943347, Loss: 0.1984, Nodes_count: 153728, Cost Time: 767.79s\n",
      "Time: 2019-05-08 20:14:01.524943347~2019-05-08 20:33:31.498044174, Loss: 0.2022, Nodes_count: 153736, Cost Time: 768.18s\n",
      "Time: 2019-05-08 20:33:31.498044174~2019-05-08 20:48:31.524002588, Loss: 0.1982, Nodes_count: 153739, Cost Time: 768.60s\n",
      "Time: 2019-05-08 20:48:31.524002588~2019-05-08 21:04:31.490231913, Loss: 0.2144, Nodes_count: 153747, Cost Time: 768.93s\n",
      "Time: 2019-05-08 21:04:31.490231913~2019-05-08 21:24:01.495025698, Loss: 0.2047, Nodes_count: 153756, Cost Time: 769.54s\n",
      "Time: 2019-05-08 21:24:01.495025698~2019-05-08 21:39:31.522563147, Loss: 0.1810, Nodes_count: 153756, Cost Time: 769.94s\n",
      "Time: 2019-05-08 21:39:31.522563147~2019-05-08 21:58:01.519005788, Loss: 0.2100, Nodes_count: 153767, Cost Time: 770.30s\n",
      "Time: 2019-05-08 21:58:01.519005788~2019-05-08 22:14:31.523095977, Loss: 0.1948, Nodes_count: 153774, Cost Time: 770.65s\n",
      "Time: 2019-05-08 22:14:31.523095977~2019-05-08 22:32:42.535693417, Loss: 0.1759, Nodes_count: 153775, Cost Time: 771.45s\n",
      "Time: 2019-05-08 22:32:42.535693417~2019-05-08 22:51:31.495982089, Loss: 0.1993, Nodes_count: 153785, Cost Time: 772.05s\n",
      "Time: 2019-05-08 22:51:31.495982089~2019-05-08 23:11:31.517681557, Loss: 0.1911, Nodes_count: 153792, Cost Time: 772.56s\n",
      "Time: 2019-05-08 23:11:31.517681557~2019-05-08 23:29:31.506809805, Loss: 0.1929, Nodes_count: 153800, Cost Time: 773.40s\n",
      "Time: 2019-05-08 23:29:31.506809805~2019-05-08 23:49:01.517454902, Loss: 0.1631, Nodes_count: 153803, Cost Time: 773.90s\n"
     ]
    }
   ],
   "source": [
    "ans_5_8=test_day_new(graph_5_8,\"graph_5_8\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "after merge: TemporalData(dst=[6898178], msg=[6898178, 41], src=[6898178], t=[6898178])\n",
      "Time: 2019-05-09 00:00:00.207323955~2019-05-09 00:15:01.493243668, Loss: 0.5768, Nodes_count: 73, Cost Time: 0.35s\n",
      "Time: 2019-05-09 00:15:01.493243668~2019-05-09 00:32:01.509088277, Loss: 0.2078, Nodes_count: 124, Cost Time: 0.61s\n",
      "Time: 2019-05-09 00:32:01.509088277~2019-05-09 00:50:31.512334564, Loss: 0.2521, Nodes_count: 138, Cost Time: 0.87s\n",
      "Time: 2019-05-09 00:50:31.512334564~2019-05-09 01:09:31.519558739, Loss: 0.2613, Nodes_count: 152, Cost Time: 1.20s\n",
      "Time: 2019-05-09 01:09:31.519558739~2019-05-09 01:28:01.511221355, Loss: 0.1977, Nodes_count: 185, Cost Time: 1.72s\n",
      "Time: 2019-05-09 01:28:01.511221355~2019-05-09 01:43:31.496122592, Loss: 0.1984, Nodes_count: 193, Cost Time: 2.03s\n",
      "Time: 2019-05-09 01:43:31.496122592~2019-05-09 02:02:31.501625321, Loss: 0.2058, Nodes_count: 204, Cost Time: 2.65s\n",
      "Time: 2019-05-09 02:02:31.501625321~2019-05-09 02:21:01.508194986, Loss: 0.1839, Nodes_count: 210, Cost Time: 2.99s\n",
      "Time: 2019-05-09 02:21:01.508194986~2019-05-09 02:41:01.496942401, Loss: 0.1736, Nodes_count: 213, Cost Time: 3.50s\n",
      "Time: 2019-05-09 02:41:01.496942401~2019-05-09 02:58:31.546557126, Loss: 0.2016, Nodes_count: 224, Cost Time: 3.95s\n",
      "Time: 2019-05-09 02:58:31.546557126~2019-05-09 03:14:31.541454570, Loss: 0.2544, Nodes_count: 232, Cost Time: 4.20s\n",
      "Time: 2019-05-09 03:14:31.541454570~2019-05-09 03:33:31.522432333, Loss: 0.1939, Nodes_count: 233, Cost Time: 4.51s\n",
      "Time: 2019-05-09 03:33:31.522432333~2019-05-09 03:49:31.487819035, Loss: 0.1943, Nodes_count: 244, Cost Time: 4.77s\n",
      "Time: 2019-05-09 03:49:31.487819035~2019-05-09 04:08:31.512408415, Loss: 0.1895, Nodes_count: 252, Cost Time: 5.12s\n",
      "Time: 2019-05-09 04:08:31.512408415~2019-05-09 04:26:01.506692561, Loss: 0.2156, Nodes_count: 262, Cost Time: 5.91s\n",
      "Time: 2019-05-09 04:26:01.506692561~2019-05-09 04:44:01.496220655, Loss: 0.2151, Nodes_count: 264, Cost Time: 6.52s\n",
      "Time: 2019-05-09 04:44:01.496220655~2019-05-09 05:03:01.500856474, Loss: 0.2243, Nodes_count: 275, Cost Time: 7.15s\n",
      "Time: 2019-05-09 05:03:01.500856474~2019-05-09 05:20:01.521604357, Loss: 0.2483, Nodes_count: 283, Cost Time: 7.55s\n",
      "Time: 2019-05-09 05:20:01.521604357~2019-05-09 05:39:31.512589142, Loss: 0.2264, Nodes_count: 283, Cost Time: 7.93s\n",
      "Time: 2019-05-09 05:39:31.512589142~2019-05-09 05:58:01.497381298, Loss: 0.2081, Nodes_count: 294, Cost Time: 8.25s\n",
      "Time: 2019-05-09 05:58:01.497381298~2019-05-09 06:16:31.498553054, Loss: 0.1988, Nodes_count: 302, Cost Time: 8.59s\n",
      "Time: 2019-05-09 06:16:31.498553054~2019-05-09 06:34:01.518723426, Loss: 0.2335, Nodes_count: 312, Cost Time: 8.98s\n",
      "Time: 2019-05-09 06:34:01.518723426~2019-05-09 06:50:01.488237695, Loss: 0.2495, Nodes_count: 315, Cost Time: 9.42s\n",
      "Time: 2019-05-09 06:50:01.488237695~2019-05-09 07:08:31.498981836, Loss: 0.2458, Nodes_count: 323, Cost Time: 9.77s\n",
      "Time: 2019-05-09 07:08:31.498981836~2019-05-09 07:27:31.511153471, Loss: 0.1810, Nodes_count: 332, Cost Time: 10.14s\n",
      "Time: 2019-05-09 07:27:31.511153471~2019-05-09 07:42:31.716512490, Loss: 0.2131, Nodes_count: 456, Cost Time: 10.64s\n",
      "Time: 2019-05-09 07:42:31.716512490~2019-05-09 07:58:01.494245825, Loss: 0.2261, Nodes_count: 483, Cost Time: 11.14s\n",
      "Time: 2019-05-09 07:58:01.494245825~2019-05-09 08:14:13.608285038, Loss: 0.2071, Nodes_count: 2280, Cost Time: 19.45s\n",
      "Time: 2019-05-09 08:14:13.608285038~2019-05-09 08:29:22.417122531, Loss: 0.2503, Nodes_count: 44265, Cost Time: 29.66s\n",
      "Time: 2019-05-09 08:29:22.417122531~2019-05-09 08:44:31.520902442, Loss: 0.3866, Nodes_count: 44720, Cost Time: 33.78s\n",
      "Time: 2019-05-09 08:44:31.520902442~2019-05-09 09:02:07.321314205, Loss: 0.3341, Nodes_count: 45306, Cost Time: 39.95s\n",
      "Time: 2019-05-09 09:02:07.321314205~2019-05-09 09:18:51.969852163, Loss: 0.3453, Nodes_count: 117689, Cost Time: 60.92s\n",
      "Time: 2019-05-09 09:18:51.969852163~2019-05-09 09:35:33.594129613, Loss: 0.7165, Nodes_count: 134368, Cost Time: 88.84s\n",
      "Time: 2019-05-09 09:35:33.594129613~2019-05-09 09:52:04.489245008, Loss: 0.1165, Nodes_count: 134701, Cost Time: 105.76s\n",
      "Time: 2019-05-09 09:52:04.489245008~2019-05-09 10:10:50.477780495, Loss: 0.1205, Nodes_count: 140070, Cost Time: 133.23s\n",
      "Time: 2019-05-09 10:10:50.477780495~2019-05-09 10:26:31.516032725, Loss: 0.1447, Nodes_count: 140268, Cost Time: 140.80s\n",
      "Time: 2019-05-09 10:26:31.516032725~2019-05-09 10:41:47.720010114, Loss: 0.1434, Nodes_count: 140498, Cost Time: 149.09s\n",
      "Time: 2019-05-09 10:41:47.720010114~2019-05-09 10:57:07.794058850, Loss: 0.1459, Nodes_count: 142057, Cost Time: 164.52s\n",
      "Time: 2019-05-09 10:57:07.794058850~2019-05-09 11:13:01.501042121, Loss: 0.1200, Nodes_count: 142284, Cost Time: 174.11s\n",
      "Time: 2019-05-09 11:13:01.501042121~2019-05-09 11:29:31.497349974, Loss: 0.0965, Nodes_count: 142410, Cost Time: 180.89s\n",
      "Time: 2019-05-09 11:29:31.497349974~2019-05-09 11:44:56.921108170, Loss: 0.2755, Nodes_count: 142483, Cost Time: 184.37s\n",
      "Time: 2019-05-09 11:44:56.921108170~2019-05-09 12:01:01.498472073, Loss: 0.0771, Nodes_count: 142722, Cost Time: 193.22s\n",
      "Time: 2019-05-09 12:01:01.498472073~2019-05-09 12:16:05.165292532, Loss: 0.1073, Nodes_count: 142793, Cost Time: 205.71s\n",
      "Time: 2019-05-09 12:16:05.165292532~2019-05-09 12:33:01.508907545, Loss: 0.2309, Nodes_count: 142847, Cost Time: 208.37s\n",
      "Time: 2019-05-09 12:33:01.508907545~2019-05-09 12:48:26.310257706, Loss: 0.1769, Nodes_count: 143090, Cost Time: 217.44s\n",
      "Time: 2019-05-09 12:48:26.310257706~2019-05-09 13:05:29.047611314, Loss: 0.2784, Nodes_count: 143137, Cost Time: 221.50s\n",
      "Time: 2019-05-09 13:05:29.047611314~2019-05-09 13:23:01.522698356, Loss: 0.1192, Nodes_count: 143349, Cost Time: 230.59s\n",
      "Time: 2019-05-09 13:23:01.522698356~2019-05-09 13:38:10.752604347, Loss: 0.1219, Nodes_count: 143514, Cost Time: 243.12s\n",
      "Time: 2019-05-09 13:38:10.752604347~2019-05-09 13:54:01.545877241, Loss: 0.2171, Nodes_count: 143678, Cost Time: 246.83s\n",
      "Time: 2019-05-09 13:54:01.545877241~2019-05-09 14:11:23.357414494, Loss: 0.1295, Nodes_count: 143904, Cost Time: 258.10s\n",
      "Time: 2019-05-09 14:11:23.357414494~2019-05-09 14:26:37.796285168, Loss: 0.2587, Nodes_count: 143982, Cost Time: 262.43s\n",
      "Time: 2019-05-09 14:26:37.796285168~2019-05-09 14:42:21.923485594, Loss: 0.1341, Nodes_count: 144129, Cost Time: 268.13s\n",
      "Time: 2019-05-09 14:42:21.923485594~2019-05-09 15:02:01.503382988, Loss: 0.1051, Nodes_count: 144321, Cost Time: 277.43s\n",
      "Time: 2019-05-09 15:02:01.503382988~2019-05-09 15:21:01.709415274, Loss: 0.0841, Nodes_count: 146506, Cost Time: 292.08s\n",
      "Time: 2019-05-09 15:21:01.709415274~2019-05-09 15:37:01.522052920, Loss: 0.1417, Nodes_count: 146612, Cost Time: 302.84s\n",
      "Time: 2019-05-09 15:37:01.522052920~2019-05-09 15:53:01.516479316, Loss: 0.0905, Nodes_count: 146700, Cost Time: 315.08s\n",
      "Time: 2019-05-09 15:53:01.516479316~2019-05-09 16:08:25.314884693, Loss: 0.1776, Nodes_count: 146776, Cost Time: 320.77s\n",
      "Time: 2019-05-09 16:08:25.314884693~2019-05-09 16:23:31.523358360, Loss: 0.2163, Nodes_count: 146897, Cost Time: 325.71s\n",
      "Time: 2019-05-09 16:23:31.523358360~2019-05-09 16:42:27.541450150, Loss: 0.1977, Nodes_count: 147069, Cost Time: 332.49s\n",
      "Time: 2019-05-09 16:42:27.541450150~2019-05-09 16:58:10.720672915, Loss: 0.1462, Nodes_count: 150651, Cost Time: 343.55s\n",
      "Time: 2019-05-09 16:58:10.720672915~2019-05-09 17:13:25.458500818, Loss: 0.1942, Nodes_count: 150897, Cost Time: 352.27s\n",
      "Time: 2019-05-09 17:13:25.458500818~2019-05-09 17:28:26.799470003, Loss: 0.2011, Nodes_count: 150975, Cost Time: 356.76s\n",
      "Time: 2019-05-09 17:28:26.799470003~2019-05-09 17:46:31.517885767, Loss: 0.0927, Nodes_count: 151091, Cost Time: 365.43s\n",
      "Time: 2019-05-09 17:46:31.517885767~2019-05-09 18:04:31.517197232, Loss: 0.1160, Nodes_count: 151123, Cost Time: 366.67s\n",
      "Time: 2019-05-09 18:04:31.517197232~2019-05-09 18:20:01.489626299, Loss: 0.1336, Nodes_count: 151305, Cost Time: 379.46s\n",
      "Time: 2019-05-09 18:20:01.489626299~2019-05-09 18:36:31.516859871, Loss: 0.1893, Nodes_count: 151349, Cost Time: 383.77s\n",
      "Time: 2019-05-09 18:36:31.516859871~2019-05-09 18:51:31.522296215, Loss: 0.0967, Nodes_count: 151586, Cost Time: 408.05s\n",
      "Time: 2019-05-09 18:51:31.522296215~2019-05-09 19:08:38.541227489, Loss: 0.1343, Nodes_count: 151821, Cost Time: 421.74s\n",
      "Time: 2019-05-09 19:08:38.541227489~2019-05-09 19:24:45.344333837, Loss: 0.1458, Nodes_count: 152224, Cost Time: 435.28s\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Time: 2019-05-09 19:24:45.344333837~2019-05-09 19:41:59.034293716, Loss: 0.2205, Nodes_count: 152323, Cost Time: 439.67s\n",
      "Time: 2019-05-09 19:41:59.034293716~2019-05-09 19:56:59.054260720, Loss: 0.0500, Nodes_count: 159406, Cost Time: 469.15s\n",
      "Time: 2019-05-09 19:56:59.054260720~2019-05-09 20:12:01.515706054, Loss: 0.0875, Nodes_count: 160289, Cost Time: 488.35s\n",
      "Time: 2019-05-09 20:12:01.515706054~2019-05-09 20:27:05.021522389, Loss: 0.1502, Nodes_count: 160464, Cost Time: 495.75s\n",
      "Time: 2019-05-09 20:27:05.021522389~2019-05-09 20:45:31.496488143, Loss: 0.1575, Nodes_count: 160655, Cost Time: 504.79s\n",
      "Time: 2019-05-09 20:45:31.496488143~2019-05-09 21:01:01.504046556, Loss: 0.1757, Nodes_count: 160829, Cost Time: 511.20s\n",
      "Time: 2019-05-09 21:01:01.504046556~2019-05-09 21:16:42.061927432, Loss: 0.0687, Nodes_count: 162965, Cost Time: 526.54s\n",
      "Time: 2019-05-09 21:16:42.061927432~2019-05-09 21:32:36.728807875, Loss: 0.1116, Nodes_count: 163095, Cost Time: 536.91s\n",
      "Time: 2019-05-09 21:32:36.728807875~2019-05-09 21:49:34.447004737, Loss: 0.0842, Nodes_count: 164521, Cost Time: 551.68s\n",
      "Time: 2019-05-09 21:49:34.447004737~2019-05-09 22:07:01.506607705, Loss: 0.1548, Nodes_count: 164655, Cost Time: 556.41s\n",
      "Time: 2019-05-09 22:07:01.506607705~2019-05-09 22:23:01.535512940, Loss: 0.1985, Nodes_count: 164758, Cost Time: 560.04s\n",
      "Time: 2019-05-09 22:23:01.535512940~2019-05-09 22:39:01.541001793, Loss: 0.1249, Nodes_count: 164937, Cost Time: 569.98s\n",
      "Time: 2019-05-09 22:39:01.541001793~2019-05-09 22:57:14.841448199, Loss: 0.0827, Nodes_count: 166447, Cost Time: 577.61s\n",
      "Time: 2019-05-09 22:57:14.841448199~2019-05-09 23:12:31.543635344, Loss: 0.1157, Nodes_count: 166607, Cost Time: 588.73s\n",
      "Time: 2019-05-09 23:12:31.543635344~2019-05-09 23:27:51.753944130, Loss: 0.1016, Nodes_count: 167730, Cost Time: 602.38s\n",
      "Time: 2019-05-09 23:27:51.753944130~2019-05-09 23:45:37.981699694, Loss: 0.1337, Nodes_count: 167948, Cost Time: 613.16s\n"
     ]
    }
   ],
   "source": [
    "\n",
    "ans_5_9=test_day_new(graph_5_9,\"graph_5_9\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "after merge: TemporalData(dst=[6488182], msg=[6488182, 41], src=[6488182], t=[6488182])\n",
      "Time: 2019-05-11 00:00:00.500131269~2019-05-11 00:15:10.585413361, Loss: 0.4904, Nodes_count: 1858, Cost Time: 3.62s\n",
      "Time: 2019-05-11 00:15:10.585413361~2019-05-11 00:31:01.430200716, Loss: 0.5182, Nodes_count: 2315, Cost Time: 10.45s\n",
      "Time: 2019-05-11 00:31:01.430200716~2019-05-11 00:46:29.482831031, Loss: 0.3334, Nodes_count: 47459, Cost Time: 22.17s\n",
      "Time: 2019-05-11 00:46:29.482831031~2019-05-11 01:01:37.064383098, Loss: 0.4335, Nodes_count: 47932, Cost Time: 26.34s\n",
      "Time: 2019-05-11 01:01:37.064383098~2019-05-11 01:16:39.942709627, Loss: 0.6927, Nodes_count: 53616, Cost Time: 32.74s\n",
      "Time: 2019-05-11 01:16:39.942709627~2019-05-11 01:32:01.462298208, Loss: 0.3355, Nodes_count: 54094, Cost Time: 40.08s\n",
      "Time: 2019-05-11 01:32:01.462298208~2019-05-11 01:47:38.109830109, Loss: 0.4132, Nodes_count: 59005, Cost Time: 48.84s\n",
      "Time: 2019-05-11 01:47:38.109830109~2019-05-11 02:03:11.829718951, Loss: 0.6972, Nodes_count: 59411, Cost Time: 55.63s\n",
      "Time: 2019-05-11 02:03:11.829718951~2019-05-11 02:18:49.612834801, Loss: 0.4613, Nodes_count: 62282, Cost Time: 63.65s\n",
      "Time: 2019-05-11 02:18:49.612834801~2019-05-11 02:34:35.963377275, Loss: 0.5054, Nodes_count: 62635, Cost Time: 67.65s\n",
      "Time: 2019-05-11 02:34:35.963377275~2019-05-11 02:51:01.459395653, Loss: 0.4192, Nodes_count: 63120, Cost Time: 74.34s\n",
      "Time: 2019-05-11 02:51:01.459395653~2019-05-11 03:06:06.971449468, Loss: 0.5891, Nodes_count: 63371, Cost Time: 77.22s\n",
      "Time: 2019-05-11 03:06:06.971449468~2019-05-11 03:22:04.391793517, Loss: 0.4479, Nodes_count: 63736, Cost Time: 81.54s\n",
      "Time: 2019-05-11 03:22:04.391793517~2019-05-11 03:37:32.924133941, Loss: 0.4819, Nodes_count: 64066, Cost Time: 85.75s\n",
      "Time: 2019-05-11 03:37:32.924133941~2019-05-11 03:52:38.714923518, Loss: 0.3568, Nodes_count: 64476, Cost Time: 92.41s\n",
      "Time: 2019-05-11 03:52:38.714923518~2019-05-11 04:09:01.471666913, Loss: 0.4732, Nodes_count: 65749, Cost Time: 98.12s\n",
      "Time: 2019-05-11 04:09:01.471666913~2019-05-11 04:25:28.350226445, Loss: 0.6235, Nodes_count: 66037, Cost Time: 100.94s\n",
      "Time: 2019-05-11 04:25:28.350226445~2019-05-11 04:41:31.612705711, Loss: 0.4686, Nodes_count: 66392, Cost Time: 105.46s\n",
      "Time: 2019-05-11 04:41:31.612705711~2019-05-11 04:56:49.395636083, Loss: 0.6656, Nodes_count: 66654, Cost Time: 108.83s\n",
      "Time: 2019-05-11 04:56:49.395636083~2019-05-11 05:13:04.898139559, Loss: 0.3579, Nodes_count: 78779, Cost Time: 118.90s\n",
      "Time: 2019-05-11 05:13:04.898139559~2019-05-11 05:29:01.492754751, Loss: 0.4736, Nodes_count: 79245, Cost Time: 124.96s\n",
      "Time: 2019-05-11 05:29:01.492754751~2019-05-11 05:45:26.427321308, Loss: 0.3440, Nodes_count: 82652, Cost Time: 134.93s\n",
      "Time: 2019-05-11 05:45:26.427321308~2019-05-11 06:00:32.541397033, Loss: 0.4330, Nodes_count: 83778, Cost Time: 144.81s\n",
      "Time: 2019-05-11 06:00:32.541397033~2019-05-11 06:16:02.917974906, Loss: 0.2970, Nodes_count: 85543, Cost Time: 160.25s\n",
      "Time: 2019-05-11 06:16:02.917974906~2019-05-11 06:32:01.493579408, Loss: 0.5806, Nodes_count: 85798, Cost Time: 163.77s\n",
      "Time: 2019-05-11 06:32:01.493579408~2019-05-11 06:48:01.495937539, Loss: 0.4477, Nodes_count: 86142, Cost Time: 169.01s\n",
      "Time: 2019-05-11 06:48:01.495937539~2019-05-11 07:03:06.190296071, Loss: 0.8358, Nodes_count: 86334, Cost Time: 170.82s\n",
      "Time: 2019-05-11 07:03:06.190296071~2019-05-11 07:18:09.159477610, Loss: 0.3091, Nodes_count: 89545, Cost Time: 182.42s\n",
      "Time: 2019-05-11 07:18:09.159477610~2019-05-11 07:35:01.101406729, Loss: 0.3570, Nodes_count: 91022, Cost Time: 190.87s\n",
      "Time: 2019-05-11 07:35:01.101406729~2019-05-11 07:50:01.504859344, Loss: 0.4624, Nodes_count: 91530, Cost Time: 196.75s\n",
      "Time: 2019-05-11 07:50:01.504859344~2019-05-11 08:05:27.045713282, Loss: 0.4831, Nodes_count: 97044, Cost Time: 207.39s\n",
      "Time: 2019-05-11 08:05:27.045713282~2019-05-11 08:21:31.505389845, Loss: 0.5859, Nodes_count: 97357, Cost Time: 210.65s\n",
      "Time: 2019-05-11 08:21:31.505389845~2019-05-11 08:37:10.242927755, Loss: 0.3401, Nodes_count: 97689, Cost Time: 217.06s\n",
      "Time: 2019-05-11 08:37:10.242927755~2019-05-11 08:52:11.577068452, Loss: 0.3168, Nodes_count: 98080, Cost Time: 224.26s\n",
      "Time: 2019-05-11 08:52:11.577068452~2019-05-11 09:07:31.497392437, Loss: 0.3233, Nodes_count: 103404, Cost Time: 235.62s\n",
      "Time: 2019-05-11 09:07:31.497392437~2019-05-11 09:23:43.378546037, Loss: 0.3347, Nodes_count: 105647, Cost Time: 246.78s\n",
      "Time: 2019-05-11 09:23:43.378546037~2019-05-11 09:39:28.743031655, Loss: 0.3293, Nodes_count: 107075, Cost Time: 256.66s\n",
      "Time: 2019-05-11 09:39:28.743031655~2019-05-11 09:55:12.543113845, Loss: 0.9064, Nodes_count: 107275, Cost Time: 258.43s\n",
      "Time: 2019-05-11 09:55:12.543113845~2019-05-11 10:10:40.816335674, Loss: 0.4251, Nodes_count: 107587, Cost Time: 262.90s\n",
      "Time: 2019-05-11 10:10:40.816335674~2019-05-11 10:26:38.131479341, Loss: 0.6040, Nodes_count: 107941, Cost Time: 268.12s\n",
      "Time: 2019-05-11 10:26:38.131479341~2019-05-11 10:43:01.494767519, Loss: 0.3296, Nodes_count: 111651, Cost Time: 279.85s\n",
      "Time: 2019-05-11 10:43:01.494767519~2019-05-11 10:58:29.047869392, Loss: 0.2856, Nodes_count: 113302, Cost Time: 290.49s\n",
      "Time: 2019-05-11 10:58:29.047869392~2019-05-11 11:14:01.491540813, Loss: 0.2755, Nodes_count: 115513, Cost Time: 301.27s\n",
      "Time: 2019-05-11 11:14:01.491540813~2019-05-11 11:29:31.376280190, Loss: 0.3514, Nodes_count: 115860, Cost Time: 307.66s\n",
      "Time: 2019-05-11 11:29:31.376280190~2019-05-11 11:45:00.345862636, Loss: 0.5850, Nodes_count: 116119, Cost Time: 310.46s\n",
      "Time: 2019-05-11 11:45:00.345862636~2019-05-11 12:01:12.133236819, Loss: 0.3719, Nodes_count: 116484, Cost Time: 316.12s\n",
      "Time: 2019-05-11 12:01:12.133236819~2019-05-11 12:16:36.422369171, Loss: 0.3911, Nodes_count: 116750, Cost Time: 321.26s\n",
      "Time: 2019-05-11 12:16:36.422369171~2019-05-11 12:32:11.330592128, Loss: 0.2815, Nodes_count: 123718, Cost Time: 333.03s\n",
      "Time: 2019-05-11 12:32:11.330592128~2019-05-11 12:47:47.220351426, Loss: 0.3538, Nodes_count: 124018, Cost Time: 339.90s\n",
      "Time: 2019-05-11 12:47:47.220351426~2019-05-11 13:03:23.643575678, Loss: 0.4044, Nodes_count: 124294, Cost Time: 344.33s\n",
      "Time: 2019-05-11 13:03:23.643575678~2019-05-11 13:18:29.629091674, Loss: 0.3739, Nodes_count: 124615, Cost Time: 349.54s\n",
      "Time: 2019-05-11 13:18:29.629091674~2019-05-11 13:33:41.349874830, Loss: 0.4243, Nodes_count: 125014, Cost Time: 354.88s\n",
      "Time: 2019-05-11 13:33:41.349874830~2019-05-11 13:48:47.890783419, Loss: 0.4605, Nodes_count: 125251, Cost Time: 358.46s\n",
      "Time: 2019-05-11 13:48:47.890783419~2019-05-11 14:04:31.519639837, Loss: 0.8332, Nodes_count: 125396, Cost Time: 360.00s\n",
      "Time: 2019-05-11 14:04:31.519639837~2019-05-11 14:19:36.223542340, Loss: 0.4195, Nodes_count: 125628, Cost Time: 363.60s\n",
      "Time: 2019-05-11 14:19:36.223542340~2019-05-11 14:34:58.512935630, Loss: 1.0585, Nodes_count: 125785, Cost Time: 364.85s\n",
      "Time: 2019-05-11 14:34:58.512935630~2019-05-11 14:50:01.493772506, Loss: 0.5696, Nodes_count: 125951, Cost Time: 367.18s\n",
      "Time: 2019-05-11 14:50:01.493772506~2019-05-11 15:05:01.505056736, Loss: 0.4816, Nodes_count: 126126, Cost Time: 370.14s\n",
      "Time: 2019-05-11 15:05:01.505056736~2019-05-11 15:20:31.495771178, Loss: 1.0522, Nodes_count: 126293, Cost Time: 371.35s\n",
      "Time: 2019-05-11 15:20:31.495771178~2019-05-11 15:37:25.002879746, Loss: 0.5125, Nodes_count: 126511, Cost Time: 373.95s\n",
      "Time: 2019-05-11 15:37:25.002879746~2019-05-11 15:52:31.494545785, Loss: 0.7416, Nodes_count: 126687, Cost Time: 375.82s\n",
      "Time: 2019-05-11 15:52:31.494545785~2019-05-11 16:08:01.493484725, Loss: 0.7836, Nodes_count: 126862, Cost Time: 377.40s\n",
      "Time: 2019-05-11 16:08:01.493484725~2019-05-11 16:23:41.450431419, Loss: 0.4983, Nodes_count: 127085, Cost Time: 380.21s\n",
      "Time: 2019-05-11 16:23:41.450431419~2019-05-11 16:39:13.198252375, Loss: 0.7912, Nodes_count: 127241, Cost Time: 381.77s\n",
      "Time: 2019-05-11 16:39:13.198252375~2019-05-11 16:55:01.500153909, Loss: 0.8145, Nodes_count: 127424, Cost Time: 383.22s\n",
      "Time: 2019-05-11 16:55:01.500153909~2019-05-11 17:11:03.959014293, Loss: 0.8021, Nodes_count: 127646, Cost Time: 384.90s\n",
      "Time: 2019-05-11 17:11:03.959014293~2019-05-11 17:27:33.517836395, Loss: 1.6560, Nodes_count: 127766, Cost Time: 385.66s\n",
      "Time: 2019-05-11 17:27:33.517836395~2019-05-11 17:43:31.490443808, Loss: 0.5496, Nodes_count: 127962, Cost Time: 388.21s\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Time: 2019-05-11 17:43:31.490443808~2019-05-11 17:59:31.493502219, Loss: 1.1501, Nodes_count: 128138, Cost Time: 389.32s\n",
      "Time: 2019-05-11 17:59:31.493502219~2019-05-11 18:15:44.708305071, Loss: 0.7298, Nodes_count: 128342, Cost Time: 391.49s\n",
      "Time: 2019-05-11 18:15:44.708305071~2019-05-11 18:32:01.493784231, Loss: 0.3838, Nodes_count: 128620, Cost Time: 395.55s\n",
      "Time: 2019-05-11 18:32:01.493784231~2019-05-11 18:47:13.969095860, Loss: 0.5678, Nodes_count: 128806, Cost Time: 398.06s\n",
      "Time: 2019-05-11 18:47:13.969095860~2019-05-11 19:03:42.787479327, Loss: 0.6009, Nodes_count: 129067, Cost Time: 400.51s\n",
      "Time: 2019-05-11 19:03:42.787479327~2019-05-11 19:19:45.328437923, Loss: 1.0256, Nodes_count: 129209, Cost Time: 401.81s\n",
      "Time: 2019-05-11 19:19:45.328437923~2019-05-11 19:36:04.866440471, Loss: 0.7971, Nodes_count: 129381, Cost Time: 403.32s\n",
      "Time: 2019-05-11 19:36:04.866440471~2019-05-11 19:51:40.042976171, Loss: 0.4378, Nodes_count: 129623, Cost Time: 406.93s\n",
      "Time: 2019-05-11 19:51:40.042976171~2019-05-11 20:07:24.862800224, Loss: 0.5086, Nodes_count: 129856, Cost Time: 409.70s\n",
      "Time: 2019-05-11 20:07:24.862800224~2019-05-11 20:24:01.506044420, Loss: 0.5342, Nodes_count: 130072, Cost Time: 412.49s\n",
      "Time: 2019-05-11 20:24:01.506044420~2019-05-11 20:39:47.303979026, Loss: 1.5690, Nodes_count: 130181, Cost Time: 413.31s\n",
      "Time: 2019-05-11 20:39:47.303979026~2019-05-11 20:55:01.495228602, Loss: 0.6141, Nodes_count: 130372, Cost Time: 415.37s\n",
      "Time: 2019-05-11 20:55:01.495228602~2019-05-11 21:11:31.496595479, Loss: 1.4390, Nodes_count: 130508, Cost Time: 416.28s\n",
      "Time: 2019-05-11 21:11:31.496595479~2019-05-11 21:28:01.492916934, Loss: 1.6258, Nodes_count: 130631, Cost Time: 417.00s\n",
      "Time: 2019-05-11 21:28:01.492916934~2019-05-11 21:44:43.279039868, Loss: 0.4678, Nodes_count: 130851, Cost Time: 420.13s\n",
      "Time: 2019-05-11 21:44:43.279039868~2019-05-11 21:59:49.871208266, Loss: 0.6083, Nodes_count: 131137, Cost Time: 423.42s\n",
      "Time: 2019-05-11 21:59:49.871208266~2019-05-11 22:15:17.913406650, Loss: 0.9996, Nodes_count: 131276, Cost Time: 424.72s\n",
      "Time: 2019-05-11 22:15:17.913406650~2019-05-11 22:30:29.105231854, Loss: 0.7925, Nodes_count: 131438, Cost Time: 426.17s\n",
      "Time: 2019-05-11 22:30:29.105231854~2019-05-11 22:45:41.943179151, Loss: 0.8661, Nodes_count: 131586, Cost Time: 427.88s\n",
      "Time: 2019-05-11 22:45:41.943179151~2019-05-11 23:02:31.492113855, Loss: 1.3902, Nodes_count: 131706, Cost Time: 428.75s\n",
      "Time: 2019-05-11 23:02:31.492113855~2019-05-11 23:17:43.542872267, Loss: 0.4759, Nodes_count: 131889, Cost Time: 431.74s\n",
      "Time: 2019-05-11 23:17:43.542872267~2019-05-11 23:33:01.508230259, Loss: 0.6645, Nodes_count: 132062, Cost Time: 433.68s\n",
      "Time: 2019-05-11 23:33:01.508230259~2019-05-11 23:48:02.369685328, Loss: 0.5600, Nodes_count: 132229, Cost Time: 436.11s\n"
     ]
    }
   ],
   "source": [
    "ans_5_11=test_day_new(graph_5_11,\"graph_5_11\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "after merge: TemporalData(dst=[13591537], msg=[13591537, 41], src=[13591537], t=[13591537])\n",
      "Time: 2019-05-14 00:00:00.216652068~2019-05-14 00:15:02.152576344, Loss: 0.2140, Nodes_count: 115823, Cost Time: 12.59s\n",
      "Time: 2019-05-14 00:15:02.152576344~2019-05-14 00:30:52.456495816, Loss: 0.4005, Nodes_count: 116237, Cost Time: 17.81s\n",
      "Time: 2019-05-14 00:30:52.456495816~2019-05-14 00:46:31.488675323, Loss: 0.3447, Nodes_count: 116665, Cost Time: 23.67s\n",
      "Time: 2019-05-14 00:46:31.488675323~2019-05-14 01:02:22.766494572, Loss: 0.2070, Nodes_count: 117163, Cost Time: 33.21s\n",
      "Time: 2019-05-14 01:02:22.766494572~2019-05-14 01:18:47.800927242, Loss: 0.1782, Nodes_count: 117448, Cost Time: 43.34s\n",
      "Time: 2019-05-14 01:18:47.800927242~2019-05-14 01:33:57.109874818, Loss: 0.3519, Nodes_count: 117893, Cost Time: 50.19s\n",
      "Time: 2019-05-14 01:33:57.109874818~2019-05-14 01:49:42.711286391, Loss: 0.1331, Nodes_count: 138660, Cost Time: 70.15s\n",
      "Time: 2019-05-14 01:49:42.711286391~2019-05-14 02:04:42.847148244, Loss: 0.1426, Nodes_count: 140997, Cost Time: 87.05s\n",
      "Time: 2019-05-14 02:04:42.847148244~2019-05-14 02:21:17.881023437, Loss: 0.4599, Nodes_count: 141332, Cost Time: 91.15s\n",
      "Time: 2019-05-14 02:21:17.881023437~2019-05-14 02:37:08.796215519, Loss: 0.1912, Nodes_count: 142788, Cost Time: 102.19s\n",
      "Time: 2019-05-14 02:37:08.796215519~2019-05-14 02:53:02.686777403, Loss: 0.1056, Nodes_count: 144511, Cost Time: 122.32s\n",
      "Time: 2019-05-14 02:53:02.686777403~2019-05-14 03:08:06.039823042, Loss: 0.3143, Nodes_count: 145216, Cost Time: 132.24s\n",
      "Time: 2019-05-14 03:08:06.039823042~2019-05-14 03:24:24.125824282, Loss: 0.4194, Nodes_count: 145513, Cost Time: 136.60s\n",
      "Time: 2019-05-14 03:24:24.125824282~2019-05-14 03:40:31.492266909, Loss: 0.5362, Nodes_count: 145841, Cost Time: 140.12s\n",
      "Time: 2019-05-14 03:40:31.492266909~2019-05-14 03:55:39.463370919, Loss: 0.3470, Nodes_count: 146249, Cost Time: 146.88s\n",
      "Time: 2019-05-14 03:55:39.463370919~2019-05-14 04:11:20.402783947, Loss: 0.1636, Nodes_count: 150094, Cost Time: 162.14s\n",
      "Time: 2019-05-14 04:11:20.402783947~2019-05-14 04:27:29.028367610, Loss: 0.3137, Nodes_count: 150415, Cost Time: 169.40s\n",
      "Time: 2019-05-14 04:27:29.028367610~2019-05-14 04:42:31.507049782, Loss: 0.3075, Nodes_count: 150717, Cost Time: 174.96s\n",
      "Time: 2019-05-14 04:42:31.507049782~2019-05-14 04:57:54.101068941, Loss: 0.5246, Nodes_count: 151015, Cost Time: 178.19s\n",
      "Time: 2019-05-14 04:57:54.101068941~2019-05-14 05:13:31.492618479, Loss: 0.1355, Nodes_count: 171417, Cost Time: 195.22s\n",
      "Time: 2019-05-14 05:13:31.492618479~2019-05-14 05:29:31.505968490, Loss: 0.3546, Nodes_count: 171785, Cost Time: 201.40s\n",
      "Time: 2019-05-14 05:29:31.505968490~2019-05-14 05:44:42.157151223, Loss: 0.2256, Nodes_count: 172142, Cost Time: 212.99s\n",
      "Time: 2019-05-14 05:44:42.157151223~2019-05-14 05:59:43.139781502, Loss: 0.4850, Nodes_count: 172464, Cost Time: 216.44s\n",
      "Time: 2019-05-14 05:59:43.139781502~2019-05-14 06:14:50.863134060, Loss: 0.3726, Nodes_count: 172768, Cost Time: 222.65s\n",
      "Time: 2019-05-14 06:14:50.863134060~2019-05-14 06:30:25.403853123, Loss: 0.3088, Nodes_count: 173132, Cost Time: 229.49s\n",
      "Time: 2019-05-14 06:30:25.403853123~2019-05-14 06:45:43.292845666, Loss: 0.3688, Nodes_count: 173440, Cost Time: 234.64s\n",
      "Time: 2019-05-14 06:45:43.292845666~2019-05-14 07:00:48.956786874, Loss: 0.1651, Nodes_count: 178031, Cost Time: 246.32s\n",
      "Time: 2019-05-14 07:00:48.956786874~2019-05-14 07:15:55.106970028, Loss: 0.3321, Nodes_count: 178329, Cost Time: 252.21s\n",
      "Time: 2019-05-14 07:15:55.106970028~2019-05-14 07:31:06.351388922, Loss: 0.3716, Nodes_count: 178615, Cost Time: 257.84s\n",
      "Time: 2019-05-14 07:31:06.351388922~2019-05-14 07:46:06.406187653, Loss: 0.4933, Nodes_count: 194457, Cost Time: 266.79s\n",
      "Time: 2019-05-14 07:46:06.406187653~2019-05-14 08:01:28.100458703, Loss: 0.5161, Nodes_count: 218033, Cost Time: 282.12s\n",
      "Time: 2019-05-14 08:01:28.100458703~2019-05-14 08:16:28.839199678, Loss: 0.5018, Nodes_count: 219548, Cost Time: 289.69s\n",
      "Time: 2019-05-14 08:16:28.839199678~2019-05-14 08:31:32.729512360, Loss: 3.1722, Nodes_count: 220563, Cost Time: 296.40s\n",
      "Time: 2019-05-14 08:31:32.729512360~2019-05-14 08:46:44.052873581, Loss: 0.1274, Nodes_count: 223312, Cost Time: 317.17s\n",
      "Time: 2019-05-14 08:46:44.052873581~2019-05-14 09:02:14.558261420, Loss: 0.3932, Nodes_count: 223618, Cost Time: 322.58s\n",
      "Time: 2019-05-14 09:02:14.558261420~2019-05-14 09:17:20.971655668, Loss: 0.5361, Nodes_count: 224861, Cost Time: 334.23s\n",
      "Time: 2019-05-14 09:17:20.971655668~2019-05-14 09:32:31.497798481, Loss: 3.3282, Nodes_count: 225931, Cost Time: 347.30s\n",
      "Time: 2019-05-14 09:32:31.497798481~2019-05-14 09:49:09.590528813, Loss: 0.4549, Nodes_count: 226185, Cost Time: 352.24s\n",
      "Time: 2019-05-14 09:49:09.590528813~2019-05-14 10:05:01.487422951, Loss: 0.4587, Nodes_count: 226435, Cost Time: 356.85s\n",
      "Time: 2019-05-14 10:05:01.487422951~2019-05-14 10:21:01.484905000, Loss: 0.4914, Nodes_count: 226651, Cost Time: 360.71s\n",
      "Time: 2019-05-14 10:21:01.484905000~2019-05-14 10:37:26.048664593, Loss: 0.3747, Nodes_count: 226884, Cost Time: 367.28s\n",
      "Time: 2019-05-14 10:37:26.048664593~2019-05-14 10:53:01.494421034, Loss: 0.4047, Nodes_count: 227097, Cost Time: 371.66s\n",
      "Time: 2019-05-14 10:53:01.494421034~2019-05-14 11:08:27.055236406, Loss: 0.2961, Nodes_count: 227347, Cost Time: 379.46s\n",
      "Time: 2019-05-14 11:08:27.055236406~2019-05-14 11:24:01.496118837, Loss: 0.2585, Nodes_count: 228240, Cost Time: 386.32s\n",
      "Time: 2019-05-14 11:24:01.496118837~2019-05-14 11:40:15.252528842, Loss: 0.2614, Nodes_count: 228519, Cost Time: 390.95s\n",
      "Time: 2019-05-14 11:40:15.252528842~2019-05-14 11:55:25.711738425, Loss: 0.2482, Nodes_count: 228910, Cost Time: 397.45s\n",
      "Time: 2019-05-14 11:55:25.711738425~2019-05-14 12:10:32.440531011, Loss: 0.1675, Nodes_count: 229430, Cost Time: 406.50s\n",
      "Time: 2019-05-14 12:10:32.440531011~2019-05-14 12:26:47.026847931, Loss: 0.2348, Nodes_count: 229782, Cost Time: 411.38s\n",
      "Time: 2019-05-14 12:26:47.026847931~2019-05-14 12:43:01.495215198, Loss: 0.0849, Nodes_count: 251852, Cost Time: 462.69s\n",
      "Time: 2019-05-14 12:43:01.495215198~2019-05-14 12:59:29.343065601, Loss: 0.1778, Nodes_count: 252085, Cost Time: 469.20s\n",
      "Time: 2019-05-14 12:59:29.343065601~2019-05-14 13:14:36.494846495, Loss: 0.1758, Nodes_count: 252413, Cost Time: 476.29s\n",
      "Time: 2019-05-14 13:14:36.494846495~2019-05-14 13:31:01.488594793, Loss: 0.1137, Nodes_count: 257768, Cost Time: 491.96s\n",
      "Time: 2019-05-14 13:31:01.488594793~2019-05-14 13:46:56.649368141, Loss: 0.1579, Nodes_count: 258251, Cost Time: 502.15s\n",
      "Time: 2019-05-14 13:46:56.649368141~2019-05-14 14:01:56.861865565, Loss: 0.0945, Nodes_count: 259633, Cost Time: 517.44s\n",
      "Time: 2019-05-14 14:01:56.861865565~2019-05-14 14:18:12.441876858, Loss: 0.0725, Nodes_count: 263279, Cost Time: 547.33s\n",
      "Time: 2019-05-14 14:18:12.441876858~2019-05-14 14:33:35.665615598, Loss: 0.2498, Nodes_count: 263633, Cost Time: 553.53s\n",
      "Time: 2019-05-14 14:33:35.665615598~2019-05-14 14:49:05.595227210, Loss: 0.1616, Nodes_count: 264051, Cost Time: 563.60s\n",
      "Time: 2019-05-14 14:49:05.595227210~2019-05-14 15:04:31.495739830, Loss: 0.0653, Nodes_count: 265872, Cost Time: 575.56s\n",
      "Time: 2019-05-14 15:04:31.495739830~2019-05-14 15:19:40.210880344, Loss: 0.0594, Nodes_count: 266578, Cost Time: 599.87s\n",
      "Time: 2019-05-14 15:19:40.210880344~2019-05-14 15:35:01.495871430, Loss: 0.1027, Nodes_count: 267273, Cost Time: 617.72s\n",
      "Time: 2019-05-14 15:35:01.495871430~2019-05-14 15:50:01.496409854, Loss: 0.1881, Nodes_count: 267693, Cost Time: 626.75s\n",
      "Time: 2019-05-14 15:50:01.496409854~2019-05-14 16:07:01.495577354, Loss: 0.1780, Nodes_count: 268033, Cost Time: 634.69s\n",
      "Time: 2019-05-14 16:07:01.495577354~2019-05-14 16:22:09.008166964, Loss: 0.0934, Nodes_count: 271364, Cost Time: 658.25s\n",
      "Time: 2019-05-14 16:22:09.008166964~2019-05-14 16:37:48.629717740, Loss: 0.0893, Nodes_count: 272556, Cost Time: 679.80s\n",
      "Time: 2019-05-14 16:37:48.629717740~2019-05-14 16:52:56.416852310, Loss: 0.0780, Nodes_count: 272979, Cost Time: 695.30s\n",
      "Time: 2019-05-14 16:52:56.416852310~2019-05-14 17:08:03.416037709, Loss: 0.1722, Nodes_count: 273287, Cost Time: 703.56s\n",
      "Time: 2019-05-14 17:08:03.416037709~2019-05-14 17:23:18.956163567, Loss: 0.0890, Nodes_count: 274632, Cost Time: 725.58s\n",
      "Time: 2019-05-14 17:23:18.956163567~2019-05-14 17:39:05.176280359, Loss: 0.0952, Nodes_count: 275760, Cost Time: 753.69s\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Time: 2019-05-14 17:39:05.176280359~2019-05-14 17:55:18.763900563, Loss: 0.0688, Nodes_count: 284023, Cost Time: 771.50s\n",
      "Time: 2019-05-14 17:55:18.763900563~2019-05-14 18:10:19.195011436, Loss: 0.1811, Nodes_count: 284367, Cost Time: 781.15s\n",
      "Time: 2019-05-14 18:10:19.195011436~2019-05-14 18:25:19.291228993, Loss: 0.1883, Nodes_count: 284815, Cost Time: 795.52s\n",
      "Time: 2019-05-14 18:25:19.291228993~2019-05-14 18:40:21.201780869, Loss: 0.1833, Nodes_count: 285126, Cost Time: 807.98s\n",
      "Time: 2019-05-14 18:40:21.201780869~2019-05-14 18:56:52.129475445, Loss: 0.1412, Nodes_count: 285559, Cost Time: 826.22s\n",
      "Time: 2019-05-14 18:56:52.129475445~2019-05-14 19:12:10.712408509, Loss: 0.1939, Nodes_count: 285752, Cost Time: 835.16s\n",
      "Time: 2019-05-14 19:12:10.712408509~2019-05-14 19:28:38.128423572, Loss: 0.2478, Nodes_count: 285983, Cost Time: 839.27s\n",
      "Time: 2019-05-14 19:28:38.128423572~2019-05-14 19:45:01.500731472, Loss: 0.1529, Nodes_count: 290209, Cost Time: 854.60s\n",
      "Time: 2019-05-14 19:45:01.500731472~2019-05-14 20:00:01.564775961, Loss: 0.1259, Nodes_count: 291986, Cost Time: 873.42s\n",
      "Time: 2019-05-14 20:00:01.564775961~2019-05-14 20:15:31.498565817, Loss: 0.1470, Nodes_count: 292396, Cost Time: 891.07s\n",
      "Time: 2019-05-14 20:15:31.498565817~2019-05-14 20:30:39.905147822, Loss: 0.0897, Nodes_count: 293779, Cost Time: 905.29s\n",
      "Time: 2019-05-14 20:30:39.905147822~2019-05-14 20:48:29.853305652, Loss: 0.1980, Nodes_count: 294093, Cost Time: 914.63s\n",
      "Time: 2019-05-14 20:48:29.853305652~2019-05-14 21:03:35.529877137, Loss: 0.2096, Nodes_count: 294339, Cost Time: 921.23s\n",
      "Time: 2019-05-14 21:03:35.529877137~2019-05-14 21:19:23.539915401, Loss: 0.0901, Nodes_count: 295923, Cost Time: 939.70s\n",
      "Time: 2019-05-14 21:19:23.539915401~2019-05-14 21:35:16.383991146, Loss: 0.1980, Nodes_count: 296150, Cost Time: 947.44s\n",
      "Time: 2019-05-14 21:35:16.383991146~2019-05-14 21:52:04.868022874, Loss: 0.1483, Nodes_count: 296443, Cost Time: 958.82s\n",
      "Time: 2019-05-14 21:52:04.868022874~2019-05-14 22:08:01.492103293, Loss: 0.1116, Nodes_count: 298124, Cost Time: 974.68s\n",
      "Time: 2019-05-14 22:08:01.492103293~2019-05-14 22:24:09.949262623, Loss: 0.1879, Nodes_count: 298300, Cost Time: 979.76s\n",
      "Time: 2019-05-14 22:24:09.949262623~2019-05-14 22:39:18.367975095, Loss: 0.0712, Nodes_count: 299158, Cost Time: 1004.43s\n",
      "Time: 2019-05-14 22:39:18.367975095~2019-05-14 22:54:58.932966824, Loss: 0.0891, Nodes_count: 299583, Cost Time: 1022.62s\n",
      "Time: 2019-05-14 22:54:58.932966824~2019-05-14 23:11:08.033781569, Loss: 0.2370, Nodes_count: 299920, Cost Time: 1029.99s\n",
      "Time: 2019-05-14 23:11:08.033781569~2019-05-14 23:27:10.374817359, Loss: 0.2582, Nodes_count: 300223, Cost Time: 1036.84s\n",
      "Time: 2019-05-14 23:27:10.374817359~2019-05-14 23:42:22.657126844, Loss: 0.3391, Nodes_count: 300399, Cost Time: 1040.21s\n",
      "Time: 2019-05-14 23:42:22.657126844~2019-05-14 23:57:53.548510363, Loss: 0.3272, Nodes_count: 300645, Cost Time: 1044.83s\n"
     ]
    }
   ],
   "source": [
    "ans_5_14=test_day_new(graph_5_14,\"graph_5_14\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "after merge: TemporalData(dst=[12310324], msg=[12310324, 41], src=[12310324], t=[12310324])\n",
      "Time: 2019-05-15 00:00:01.490408727~2019-05-15 00:16:14.833595653, Loss: 0.1283, Nodes_count: 1544, Cost Time: 13.10s\n",
      "Time: 2019-05-15 00:16:14.833595653~2019-05-15 00:32:01.492056162, Loss: 0.1593, Nodes_count: 2670, Cost Time: 24.28s\n",
      "Time: 2019-05-15 00:32:01.492056162~2019-05-15 00:47:15.554515213, Loss: 0.3074, Nodes_count: 2893, Cost Time: 28.64s\n",
      "Time: 2019-05-15 00:47:15.554515213~2019-05-15 01:04:31.491761640, Loss: 0.3658, Nodes_count: 3099, Cost Time: 30.99s\n",
      "Time: 2019-05-15 01:04:31.491761640~2019-05-15 01:20:01.492131631, Loss: 0.1360, Nodes_count: 3276, Cost Time: 38.12s\n",
      "Time: 2019-05-15 01:20:01.492131631~2019-05-15 01:36:01.495126517, Loss: 0.1904, Nodes_count: 3536, Cost Time: 45.42s\n",
      "Time: 2019-05-15 01:36:01.495126517~2019-05-15 01:51:02.896532154, Loss: 0.2650, Nodes_count: 3830, Cost Time: 51.22s\n",
      "Time: 2019-05-15 01:51:02.896532154~2019-05-15 02:07:19.144870551, Loss: 0.1613, Nodes_count: 79255, Cost Time: 65.16s\n",
      "Time: 2019-05-15 02:07:19.144870551~2019-05-15 02:23:18.291403804, Loss: 0.2835, Nodes_count: 79530, Cost Time: 69.80s\n",
      "Time: 2019-05-15 02:23:18.291403804~2019-05-15 02:39:26.758938680, Loss: 0.2524, Nodes_count: 79822, Cost Time: 75.27s\n",
      "Time: 2019-05-15 02:39:26.758938680~2019-05-15 02:54:29.939561154, Loss: 0.1040, Nodes_count: 99877, Cost Time: 91.05s\n",
      "Time: 2019-05-15 02:54:29.939561154~2019-05-15 03:09:30.148005357, Loss: 0.0971, Nodes_count: 106760, Cost Time: 108.51s\n",
      "Time: 2019-05-15 03:09:30.148005357~2019-05-15 03:25:02.394441209, Loss: 0.1044, Nodes_count: 108498, Cost Time: 127.47s\n",
      "Time: 2019-05-15 03:25:02.394441209~2019-05-15 03:41:44.920119418, Loss: 0.2043, Nodes_count: 108768, Cost Time: 135.09s\n",
      "Time: 2019-05-15 03:41:44.920119418~2019-05-15 03:58:07.697665053, Loss: 0.1186, Nodes_count: 109051, Cost Time: 148.13s\n",
      "Time: 2019-05-15 03:58:07.697665053~2019-05-15 04:14:56.274252703, Loss: 0.1488, Nodes_count: 109336, Cost Time: 157.87s\n",
      "Time: 2019-05-15 04:14:56.274252703~2019-05-15 04:31:01.490574676, Loss: 0.1698, Nodes_count: 109546, Cost Time: 164.65s\n",
      "Time: 2019-05-15 04:31:01.490574676~2019-05-15 04:46:31.301354716, Loss: 0.2971, Nodes_count: 109724, Cost Time: 168.48s\n",
      "Time: 2019-05-15 04:46:31.301354716~2019-05-15 05:01:36.395374506, Loss: 0.3591, Nodes_count: 109882, Cost Time: 170.53s\n",
      "Time: 2019-05-15 05:01:36.395374506~2019-05-15 05:17:01.503229576, Loss: 0.1838, Nodes_count: 110073, Cost Time: 177.07s\n",
      "Time: 2019-05-15 05:17:01.503229576~2019-05-15 05:32:11.337521289, Loss: 0.3910, Nodes_count: 110244, Cost Time: 179.23s\n",
      "Time: 2019-05-15 05:32:11.337521289~2019-05-15 05:48:01.503688497, Loss: 0.3106, Nodes_count: 110478, Cost Time: 183.40s\n",
      "Time: 2019-05-15 05:48:01.503688497~2019-05-15 06:05:01.495772298, Loss: 0.3347, Nodes_count: 110709, Cost Time: 186.61s\n",
      "Time: 2019-05-15 06:05:01.495772298~2019-05-15 06:20:51.005863855, Loss: 0.2670, Nodes_count: 111046, Cost Time: 192.50s\n",
      "Time: 2019-05-15 06:20:51.005863855~2019-05-15 06:36:01.491983616, Loss: 0.3496, Nodes_count: 111214, Cost Time: 195.11s\n",
      "Time: 2019-05-15 06:36:01.491983616~2019-05-15 06:53:31.493116975, Loss: 0.1567, Nodes_count: 111500, Cost Time: 202.00s\n",
      "Time: 2019-05-15 06:53:31.493116975~2019-05-15 07:09:55.168118324, Loss: 0.2685, Nodes_count: 112628, Cost Time: 206.72s\n",
      "Time: 2019-05-15 07:09:55.168118324~2019-05-15 07:27:01.254806380, Loss: 0.5293, Nodes_count: 112769, Cost Time: 208.12s\n",
      "Time: 2019-05-15 07:27:01.254806380~2019-05-15 07:42:05.122895776, Loss: 0.0797, Nodes_count: 121941, Cost Time: 221.76s\n",
      "Time: 2019-05-15 07:42:05.122895776~2019-05-15 07:57:29.435273604, Loss: 0.4085, Nodes_count: 213125, Cost Time: 245.94s\n",
      "Time: 2019-05-15 07:57:29.435273604~2019-05-15 08:12:40.385079790, Loss: 0.1716, Nodes_count: 213403, Cost Time: 256.03s\n",
      "Time: 2019-05-15 08:12:40.385079790~2019-05-15 08:28:58.370499520, Loss: 0.1033, Nodes_count: 219211, Cost Time: 273.63s\n",
      "Time: 2019-05-15 08:28:58.370499520~2019-05-15 08:46:17.912177800, Loss: 0.1182, Nodes_count: 219943, Cost Time: 287.37s\n",
      "Time: 2019-05-15 08:46:17.912177800~2019-05-15 09:01:36.712206897, Loss: 0.0644, Nodes_count: 221269, Cost Time: 333.09s\n",
      "Time: 2019-05-15 09:01:36.712206897~2019-05-15 09:18:20.052280739, Loss: 0.0891, Nodes_count: 222259, Cost Time: 367.36s\n",
      "Time: 2019-05-15 09:18:20.052280739~2019-05-15 09:33:20.409598023, Loss: 0.1629, Nodes_count: 223008, Cost Time: 392.49s\n",
      "Time: 2019-05-15 09:33:20.409598023~2019-05-15 09:48:20.851554754, Loss: 0.2978, Nodes_count: 223266, Cost Time: 398.25s\n",
      "Time: 2019-05-15 09:48:20.851554754~2019-05-15 10:04:07.712341272, Loss: 0.0944, Nodes_count: 225757, Cost Time: 427.66s\n",
      "Time: 2019-05-15 10:04:07.712341272~2019-05-15 10:19:12.055930735, Loss: 0.0811, Nodes_count: 226533, Cost Time: 464.87s\n",
      "Time: 2019-05-15 10:19:12.055930735~2019-05-15 10:34:12.998931412, Loss: 0.1769, Nodes_count: 226904, Cost Time: 478.02s\n",
      "Time: 2019-05-15 10:34:12.998931412~2019-05-15 10:52:01.493441398, Loss: 0.2471, Nodes_count: 227239, Cost Time: 486.02s\n",
      "Time: 2019-05-15 10:52:01.493441398~2019-05-15 11:07:01.494486145, Loss: 0.1227, Nodes_count: 228988, Cost Time: 502.15s\n",
      "Time: 2019-05-15 11:07:01.494486145~2019-05-15 11:22:08.001455967, Loss: 0.1541, Nodes_count: 229450, Cost Time: 516.00s\n",
      "Time: 2019-05-15 11:22:08.001455967~2019-05-15 11:38:31.497341568, Loss: 0.2267, Nodes_count: 229804, Cost Time: 523.34s\n",
      "Time: 2019-05-15 11:38:31.497341568~2019-05-15 11:54:52.383589579, Loss: 0.0861, Nodes_count: 230238, Cost Time: 549.13s\n",
      "Time: 2019-05-15 11:54:52.383589579~2019-05-15 13:27:01.496190252, Loss: 0.0233, Nodes_count: 232085, Cost Time: 561.68s\n",
      "Time: 2019-05-15 13:27:01.496190252~2019-05-15 13:42:24.177751369, Loss: 0.3940, Nodes_count: 235626, Cost Time: 617.81s\n",
      "Time: 2019-05-15 13:42:24.177751369~2019-05-15 13:58:15.520482252, Loss: 0.5167, Nodes_count: 236651, Cost Time: 633.06s\n",
      "Time: 2019-05-15 13:58:15.520482252~2019-05-15 14:13:37.257086895, Loss: 7.4043, Nodes_count: 238954, Cost Time: 660.32s\n",
      "Time: 2019-05-15 14:13:37.257086895~2019-05-15 14:29:18.996669142, Loss: 0.1715, Nodes_count: 239536, Cost Time: 681.61s\n",
      "Time: 2019-05-15 14:29:18.996669142~2019-05-15 14:44:51.773840192, Loss: 0.1887, Nodes_count: 239832, Cost Time: 690.74s\n",
      "Time: 2019-05-15 14:44:51.773840192~2019-05-15 15:00:26.765466538, Loss: 2.5431, Nodes_count: 240939, Cost Time: 714.81s\n",
      "Time: 2019-05-15 15:00:26.765466538~2019-05-15 15:17:03.203703087, Loss: 0.3624, Nodes_count: 241316, Cost Time: 721.01s\n",
      "Time: 2019-05-15 15:17:03.203703087~2019-05-15 15:34:25.452570637, Loss: 0.0765, Nodes_count: 241635, Cost Time: 741.17s\n",
      "Time: 2019-05-15 15:34:25.452570637~2019-05-15 15:49:43.447021039, Loss: 0.1666, Nodes_count: 241797, Cost Time: 750.84s\n",
      "Time: 2019-05-15 15:49:43.447021039~2019-05-15 16:05:41.064452218, Loss: 0.1455, Nodes_count: 242067, Cost Time: 759.46s\n",
      "Time: 2019-05-15 16:05:41.064452218~2019-05-15 16:22:39.979479840, Loss: 0.1828, Nodes_count: 242202, Cost Time: 763.48s\n",
      "Time: 2019-05-15 16:22:39.979479840~2019-05-15 16:38:00.022566187, Loss: 0.1258, Nodes_count: 242408, Cost Time: 775.14s\n",
      "Time: 2019-05-15 16:38:00.022566187~2019-05-15 16:54:31.494483643, Loss: 0.1587, Nodes_count: 242698, Cost Time: 788.41s\n",
      "Time: 2019-05-15 16:54:31.494483643~2019-05-15 17:10:01.626108726, Loss: 0.0636, Nodes_count: 242859, Cost Time: 807.44s\n",
      "Time: 2019-05-15 17:10:01.626108726~2019-05-15 17:25:14.590228152, Loss: 0.1773, Nodes_count: 243111, Cost Time: 815.34s\n",
      "Time: 2019-05-15 17:25:14.590228152~2019-05-15 17:43:54.631759423, Loss: 0.0934, Nodes_count: 243342, Cost Time: 836.71s\n",
      "Time: 2019-05-15 17:43:54.631759423~2019-05-15 18:00:21.533587327, Loss: 0.2107, Nodes_count: 243514, Cost Time: 843.96s\n",
      "Time: 2019-05-15 18:00:21.533587327~2019-05-15 18:16:33.957928738, Loss: 0.0529, Nodes_count: 243785, Cost Time: 878.63s\n",
      "Time: 2019-05-15 18:16:33.957928738~2019-05-15 18:32:44.229252473, Loss: 0.0914, Nodes_count: 243999, Cost Time: 898.63s\n",
      "Time: 2019-05-15 18:32:44.229252473~2019-05-15 18:50:02.896672585, Loss: 0.1719, Nodes_count: 244136, Cost Time: 902.40s\n",
      "Time: 2019-05-15 18:50:02.896672585~2019-05-15 19:05:15.589701783, Loss: 0.1415, Nodes_count: 244358, Cost Time: 908.35s\n",
      "Time: 2019-05-15 19:05:15.589701783~2019-05-15 19:21:31.509532475, Loss: 0.1234, Nodes_count: 244577, Cost Time: 918.64s\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Time: 2019-05-15 19:21:31.509532475~2019-05-15 19:37:24.849404892, Loss: 0.0564, Nodes_count: 244683, Cost Time: 930.84s\n",
      "Time: 2019-05-15 19:37:24.849404892~2019-05-15 19:56:19.975334466, Loss: 0.1264, Nodes_count: 244849, Cost Time: 946.12s\n",
      "Time: 2019-05-15 19:56:19.975334466~2019-05-15 20:12:58.479720072, Loss: 0.1394, Nodes_count: 245209, Cost Time: 961.06s\n",
      "Time: 2019-05-15 20:12:58.479720072~2019-05-15 20:28:31.496181001, Loss: 0.1317, Nodes_count: 245443, Cost Time: 973.16s\n",
      "Time: 2019-05-15 20:28:31.496181001~2019-05-15 20:45:02.944896082, Loss: 0.1151, Nodes_count: 245578, Cost Time: 982.35s\n",
      "Time: 2019-05-15 20:45:02.944896082~2019-05-15 21:00:14.411230352, Loss: 0.0960, Nodes_count: 245851, Cost Time: 1007.44s\n",
      "Time: 2019-05-15 21:00:14.411230352~2019-05-15 21:16:04.951215086, Loss: 0.0954, Nodes_count: 246079, Cost Time: 1026.95s\n",
      "Time: 2019-05-15 21:16:04.951215086~2019-05-15 21:31:25.960086974, Loss: 0.1711, Nodes_count: 246300, Cost Time: 1034.64s\n",
      "Time: 2019-05-15 21:31:25.960086974~2019-05-15 21:47:41.306583947, Loss: 0.2020, Nodes_count: 246527, Cost Time: 1041.82s\n",
      "Time: 2019-05-15 21:47:41.306583947~2019-05-15 22:03:31.522168702, Loss: 0.1883, Nodes_count: 246637, Cost Time: 1046.22s\n",
      "Time: 2019-05-15 22:03:31.522168702~2019-05-15 22:19:16.263929035, Loss: 0.1692, Nodes_count: 246740, Cost Time: 1057.39s\n",
      "Time: 2019-05-15 22:19:16.263929035~2019-05-15 22:37:52.734006062, Loss: 0.1042, Nodes_count: 246864, Cost Time: 1067.65s\n",
      "Time: 2019-05-15 22:37:52.734006062~2019-05-15 22:55:31.494815444, Loss: 0.1941, Nodes_count: 247066, Cost Time: 1073.70s\n",
      "Time: 2019-05-15 22:55:31.494815444~2019-05-15 23:11:23.284826570, Loss: 0.1041, Nodes_count: 247306, Cost Time: 1086.25s\n",
      "Time: 2019-05-15 23:11:23.284826570~2019-05-15 23:29:31.512587396, Loss: 0.1499, Nodes_count: 247400, Cost Time: 1100.32s\n",
      "Time: 2019-05-15 23:29:31.512587396~2019-05-15 23:46:09.097590467, Loss: 0.2431, Nodes_count: 247466, Cost Time: 1103.40s\n"
     ]
    }
   ],
   "source": [
    "ans_5_15=test_day_new(graph_5_15,\"graph_5_15\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Initialize the node IDF"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████████████████████████████████████████████████████████████████████████████████████| 85/85 [02:06<00:00,  1.49s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "IDF weight calculate complete!\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "\n",
    "node_set=set()\n",
    "\n",
    "file_list=[]\n",
    "\n",
    "file_path=\"graph_5_9/\"\n",
    "file_l=os.listdir(\"graph_5_9/\")\n",
    "for i in file_l:\n",
    "    file_list.append(file_path+i)\n",
    "\n",
    "\n",
    "node_IDF={}\n",
    "node_set = {}\n",
    "for f_path in tqdm(file_list):\n",
    "    f=open(f_path)\n",
    "    for line in f:\n",
    "        l=line.strip()\n",
    "        jdata=eval(l)\n",
    "        jdata=eval(l)\n",
    "        if jdata['loss']>0:\n",
    "            if 'netflow' not in str(jdata['srcmsg']):\n",
    "                if str(jdata['srcmsg']) not in node_set.keys():\n",
    "                    node_set[str(jdata['srcmsg'])] = set([f_path])\n",
    "                else:\n",
    "                    node_set[str(jdata['srcmsg'])].add(f_path)\n",
    "            if 'netflow' not in str(jdata['dstmsg']):\n",
    "                if str(jdata['dstmsg']) not in node_set.keys():\n",
    "                    node_set[str(jdata['dstmsg'])] = set([f_path])\n",
    "                else:\n",
    "                    node_set[str(jdata['dstmsg'])].add(f_path)\n",
    "for n in node_set:\n",
    "    include_count = len(node_set[n])   \n",
    "    IDF=math.log(len(file_list)/(include_count+1))\n",
    "    node_IDF[n] = IDF    \n",
    "\n",
    "\n",
    "torch.save(node_IDF,\"node_IDF\")\n",
    "print(\"IDF weight calculate complete!\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "def cal_train_IDF(find_str,file_list):\n",
    "    include_count=0\n",
    "    for f_path in (file_list):\n",
    "        f=open(f_path)\n",
    "        if find_str in f.read():\n",
    "            include_count+=1             \n",
    "    IDF=math.log(len(file_list)/(include_count+1))\n",
    "    return IDF\n",
    "\n",
    "\n",
    "def cal_IDF(find_str,file_path,file_list):\n",
    "    file_list=os.listdir(file_path)\n",
    "    include_count=0\n",
    "    different_neighbor=set()\n",
    "    for f_path in (file_list):\n",
    "        f=open(file_path+f_path)\n",
    "        if find_str in f.read():\n",
    "            include_count+=1                \n",
    "                \n",
    "    IDF=math.log(len(file_list)/(include_count+1))\n",
    "    \n",
    "    return IDF,1\n",
    "\n",
    "def cal_redundant(find_str,edge_list):\n",
    "    \n",
    "    different_neighbor=set()\n",
    "    for e in edge_list:\n",
    "        if find_str in str(e):\n",
    "            different_neighbor.add(e[0])\n",
    "            different_neighbor.add(e[1])\n",
    "    return len(different_neighbor)-2\n",
    "\n",
    "def cal_anomaly_loss(loss_list,edge_list,file_path):\n",
    "    \n",
    "    if len(loss_list)!=len(edge_list):\n",
    "        print(\"error!\")\n",
    "        return 0\n",
    "    count=0\n",
    "    loss_sum=0\n",
    "    loss_std=std(loss_list)\n",
    "    loss_mean=mean(loss_list)\n",
    "    edge_set=set()\n",
    "    node_set=set()\n",
    "    node2redundant={}\n",
    "    \n",
    "    thr=loss_mean+1.5*loss_std\n",
    "\n",
    "    print(\"thr:\",thr)\n",
    "\n",
    "    for i in range(len(loss_list)):\n",
    "        if loss_list[i]>thr:\n",
    "            count+=1\n",
    "            src_node=edge_list[i][0]\n",
    "            dst_node=edge_list[i][1]\n",
    "            \n",
    "            loss_sum+=loss_list[i]\n",
    "    \n",
    "            node_set.add(src_node)\n",
    "            node_set.add(dst_node)\n",
    "            edge_set.add(edge_list[i][0]+edge_list[i][1])\n",
    "    return count, loss_sum/count,node_set,edge_set\n",
    "#     return count, count/len(loss_list)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Construct the relations between time windows"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "def is_include_key_word(s):\n",
    "    keywords=[\n",
    "         'netflow',\n",
    "        '/dev/pts',\n",
    "         'proc',\n",
    "      ]\n",
    "    flag=False\n",
    "    for i in keywords:\n",
    "        if i in s:\n",
    "            flag=True\n",
    "    return flag\n",
    "\n",
    "\n",
    "def cal_set_rel(s1,s2,file_list):\n",
    "    new_s=s1 & s2\n",
    "    count=0\n",
    "    for i in new_s:\n",
    "\n",
    "        if is_include_key_word(i) is not True:\n",
    "\n",
    "            if i in node_IDF.keys():\n",
    "                IDF=node_IDF[i]\n",
    "            else:\n",
    "                IDF=math.log(len(file_list)/(1))\n",
    "\n",
    "            if (IDF)>4.5 :\n",
    "                print(\"node:\",i,\" IDF:\",IDF)\n",
    "                count+=1\n",
    "    return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# label generation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [],
   "source": [
    "labels={}\n",
    "pred_label={}    \n",
    "    \n",
    "filelist = os.listdir(\"graph_5_14\")\n",
    "for f in filelist:\n",
    "    labels[\"graph_5_14/\"+f]=0\n",
    "    pred_label[\"graph_5_14/\"+f]=0\n",
    "\n",
    "filelist = os.listdir(\"graph_5_15\")\n",
    "for f in filelist:\n",
    "    labels[\"graph_5_15/\"+f]=0\n",
    "    pred_label[\"graph_5_15/\"+f]=0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [],
   "source": [
    "attack_list=[\n",
    "    'graph_5_15/2019-05-15 13:58:15.520482252~2019-05-15 14:13:37.257086895.txt',\n",
    "    'graph_5_15/2019-05-15 14:44:51.773840192~2019-05-15 15:00:26.765466538.txt',\n",
    "]\n",
    "\n",
    "for i in attack_list:\n",
    "    labels[i]=1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 5-11 validation set"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "index_count: 0\n",
      "thr: 2.1530123801161127\n",
      "graph_5_11/2019-05-11 00:00:00.500131269~2019-05-11 00:15:10.585413361.txt    3.980468719396712  count: 4651  percentage: 0.0769829184322034  node count: 106  edge count: 120\n",
      "index_count: 1\n",
      "thr: 2.4048257011206213\n",
      "graph_5_11/2019-05-11 00:15:10.585413361~2019-05-11 00:31:01.430200716.txt    4.477715654731948  count: 5077  percentage: 0.07996786794354839  node count: 96  edge count: 108\n",
      "index_count: 2\n",
      "thr: 1.673471263332857\n",
      "graph_5_11/2019-05-11 00:31:01.430200716~2019-05-11 00:46:29.482831031.txt    3.9595721705290523  count: 6850  percentage: 0.047108824823943664  node count: 135  edge count: 150\n",
      "index_count: 3\n",
      "thr: 2.1552962376929883\n",
      "graph_5_11/2019-05-11 00:46:29.482831031~2019-05-11 01:01:37.064383098.txt    4.119590005644783  count: 4647  percentage: 0.0796155427631579  node count: 92  edge count: 101\n",
      "index_count: 4\n",
      "thr: 2.7078894171329613\n",
      "graph_5_11/2019-05-11 01:01:37.064383098~2019-05-11 01:16:39.942709627.txt    4.143359333742588  count: 10492  percentage: 0.10144647277227722  node count: 103  edge count: 111\n",
      "index_count: 5\n",
      "thr: 1.7912055048629223\n",
      "graph_5_11/2019-05-11 01:16:39.942709627~2019-05-11 01:32:01.462298208.txt    4.211801867779716  count: 5599  percentage: 0.04970703125  node count: 127  edge count: 140\n",
      "index_count: 6\n",
      "thr: 2.431541165431549\n",
      "graph_5_11/2019-05-11 01:32:01.462298208~2019-05-11 01:47:38.109830109.txt    5.128484290728158  count: 7093  percentage: 0.057722981770833334  node count: 2001  edge count: 2009\n",
      "index_count: 7\n",
      "thr: 3.4586091835902106\n",
      "graph_5_11/2019-05-11 01:47:38.109830109~2019-05-11 02:03:11.829718951.txt    6.602644764211479  count: 7415  percentage: 0.072412109375  node count: 3421  edge count: 3428\n",
      "index_count: 8\n",
      "thr: 2.445230281102992\n",
      "graph_5_11/2019-05-11 02:03:11.829718951~2019-05-11 02:18:49.612834801.txt    4.577765095901761  count: 8443  percentage: 0.07705716997663552  node count: 2368  edge count: 2376\n",
      "index_count: 9\n",
      "thr: 2.4168029342636217\n",
      "graph_5_11/2019-05-11 02:18:49.612834801~2019-05-11 02:34:35.963377275.txt    4.2938465188316695  count: 5293  percentage: 0.09068325109649122  node count: 103  edge count: 111\n",
      "index_count: 10\n",
      "thr: 2.1441373661271945\n",
      "graph_5_11/2019-05-11 02:34:35.963377275~2019-05-11 02:51:01.459395653.txt    4.440255041106367  count: 6528  percentage: 0.06311881188118812  node count: 115  edge count: 127\n",
      "index_count: 11\n",
      "thr: 2.626423560112481\n",
      "graph_5_11/2019-05-11 02:51:01.459395653~2019-05-11 03:06:06.971449468.txt    4.101915918542292  count: 4707  percentage: 0.1149169921875  node count: 77  edge count: 84\n",
      "index_count: 12\n",
      "thr: 2.177329310505022\n",
      "graph_5_11/2019-05-11 03:06:06.971449468~2019-05-11 03:22:04.391793517.txt    4.0968968632052825  count: 5380  percentage: 0.07960464015151515  node count: 97  edge count: 110\n",
      "index_count: 13\n",
      "thr: 2.228937357044175\n",
      "graph_5_11/2019-05-11 03:22:04.391793517~2019-05-11 03:37:32.924133941.txt    4.115309919337591  count: 5129  percentage: 0.0795045882936508  node count: 103  edge count: 116\n",
      "index_count: 14\n",
      "thr: 1.8017787117116768\n",
      "graph_5_11/2019-05-11 03:37:32.924133941~2019-05-11 03:52:38.714923518.txt    4.086436751665838  count: 5204  percentage: 0.051857461734693876  node count: 109  edge count: 121\n",
      "index_count: 15\n",
      "thr: 2.231384706448042\n",
      "graph_5_11/2019-05-11 03:52:38.714923518~2019-05-11 04:09:01.471666913.txt    4.208142262073009  count: 6751  percentage: 0.07666015625  node count: 259  edge count: 280\n",
      "index_count: 16\n",
      "thr: 2.749227274027025\n",
      "graph_5_11/2019-05-11 04:09:01.471666913~2019-05-11 04:25:28.350226445.txt    4.210821192646287  count: 5134  percentage: 0.12228467987804878  node count: 95  edge count: 104\n",
      "index_count: 17\n",
      "thr: 2.267433420440032\n",
      "graph_5_11/2019-05-11 04:25:28.350226445~2019-05-11 04:41:31.612705711.txt    4.461089675807989  count: 5162  percentage: 0.07201450892857143  node count: 112  edge count: 121\n",
      "index_count: 18\n",
      "thr: 2.6636413014102756\n",
      "graph_5_11/2019-05-11 04:41:31.612705711~2019-05-11 04:56:49.395636083.txt    4.35056328502464  count: 5190  percentage: 0.0993795955882353  node count: 79  edge count: 87\n",
      "index_count: 19\n",
      "thr: 2.0409366149695174\n",
      "graph_5_11/2019-05-11 04:56:49.395636083~2019-05-11 05:13:04.898139559.txt    4.574507888764967  count: 7701  percentage: 0.05410437275179856  node count: 1873  edge count: 1889\n",
      "index_count: 20\n",
      "thr: 2.268186177426009\n",
      "graph_5_11/2019-05-11 05:13:04.898139559~2019-05-11 05:29:01.492754751.txt    4.416441831170014  count: 6286  percentage: 0.07055944683908046  node count: 98  edge count: 114\n",
      "index_count: 21\n",
      "thr: 1.9131847533000692\n",
      "graph_5_11/2019-05-11 05:29:01.492754751~2019-05-11 05:45:26.427321308.txt    4.106894324733832  count: 8560  percentage: 0.060139388489208634  node count: 2366  edge count: 2382\n",
      "index_count: 22\n",
      "thr: 2.6935030825550377\n",
      "graph_5_11/2019-05-11 05:45:26.427321308~2019-05-11 06:00:32.541397033.txt    5.636600474047012  count: 8886  percentage: 0.06198381696428571  node count: 3930  edge count: 3936\n",
      "index_count: 23\n",
      "thr: 1.7765786778869332\n",
      "graph_5_11/2019-05-11 06:00:32.541397033~2019-05-11 06:16:02.917974906.txt    4.023628586503518  count: 10970  percentage: 0.05175309480676329  node count: 2534  edge count: 2549\n",
      "index_count: 24\n",
      "thr: 2.547726848885832\n",
      "graph_5_11/2019-05-11 06:16:02.917974906~2019-05-11 06:32:01.493579408.txt    4.16881843997147  count: 4903  percentage: 0.10408882472826086  node count: 98  edge count: 107\n",
      "index_count: 25\n",
      "thr: 2.1749226277743205\n",
      "graph_5_11/2019-05-11 06:32:01.493579408~2019-05-11 06:48:01.495937539.txt    4.342168583225072  count: 5812  percentage: 0.06921684451219512  node count: 119  edge count: 130\n",
      "index_count: 26\n",
      "thr: 3.236132955126446\n",
      "graph_5_11/2019-05-11 06:48:01.495937539~2019-05-11 07:03:06.190296071.txt    4.2372418447226154  count: 3959  percentage: 0.1546484375  node count: 104  edge count: 108\n",
      "index_count: 27\n",
      "thr: 1.9267922231287948\n",
      "graph_5_11/2019-05-11 07:03:06.190296071~2019-05-11 07:18:09.159477610.txt    4.57093021343047  count: 7683  percentage: 0.0457495712652439  node count: 1814  edge count: 1824\n",
      "index_count: 28\n",
      "thr: 1.9320074946567696\n",
      "graph_5_11/2019-05-11 07:18:09.159477610~2019-05-11 07:35:01.101406729.txt    3.9434080303216676  count: 8084  percentage: 0.06925027412280702  node count: 2359  edge count: 2377\n",
      "index_count: 29\n",
      "thr: 2.264106039586263\n",
      "graph_5_11/2019-05-11 07:35:01.101406729~2019-05-11 07:50:01.504859344.txt    4.424574391421895  count: 6023  percentage: 0.07002185639880952  node count: 187  edge count: 223\n",
      "index_count: 30\n",
      "thr: 2.428430375522456\n",
      "graph_5_11/2019-05-11 07:50:01.504859344~2019-05-11 08:05:27.045713282.txt    4.921228281803395  count: 9765  percentage: 0.060355270965189875  node count: 726  edge count: 809\n",
      "index_count: 31\n",
      "thr: 2.5715359944862217\n",
      "graph_5_11/2019-05-11 08:05:27.045713282~2019-05-11 08:21:31.505389845.txt    4.134204341131133  count: 4934  percentage: 0.10950816761363637  node count: 76  edge count: 80\n",
      "index_count: 32\n",
      "thr: 1.814738080250251\n",
      "graph_5_11/2019-05-11 08:21:31.505389845~2019-05-11 08:37:10.242927755.txt    4.221825739740206  count: 5326  percentage: 0.05201171875  node count: 95  edge count: 107\n",
      "index_count: 33\n",
      "thr: 1.741056460551925\n",
      "graph_5_11/2019-05-11 08:37:10.242927755~2019-05-11 08:52:11.577068452.txt    4.160441056158214  count: 5243  percentage: 0.04923189603365385  node count: 97  edge count: 109\n",
      "index_count: 34\n",
      "thr: 2.258940119478575\n",
      "graph_5_11/2019-05-11 08:52:11.577068452~2019-05-11 09:07:31.497392437.txt    5.535434108100371  count: 6916  percentage: 0.04194972826086957  node count: 1982  edge count: 1993\n",
      "index_count: 35\n",
      "thr: 2.1229250584912123\n",
      "graph_5_11/2019-05-11 09:07:31.497392437~2019-05-11 09:23:43.378546037.txt    4.792200498723398  count: 7899  percentage: 0.051085213162251654  node count: 1839  edge count: 1847\n",
      "index_count: 36\n",
      "thr: 2.2002549998314542\n",
      "graph_5_11/2019-05-11 09:23:43.378546037~2019-05-11 09:39:28.743031655.txt    4.850633420986232  count: 7036  percentage: 0.05285456730769231  node count: 1656  edge count: 1669\n",
      "index_count: 37\n",
      "thr: 3.3855065173904335\n",
      "graph_5_11/2019-05-11 09:39:28.743031655~2019-05-11 09:55:12.543113845.txt    4.395200675844408  count: 3069  percentage: 0.13623046875  node count: 54  edge count: 57\n",
      "index_count: 38\n",
      "thr: 2.067143618082883\n",
      "graph_5_11/2019-05-11 09:55:12.543113845~2019-05-11 10:10:40.816335674.txt    4.166667220148816  count: 4890  percentage: 0.06821986607142858  node count: 75  edge count: 83\n",
      "index_count: 39\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "thr: 2.8272419912778974\n",
      "graph_5_11/2019-05-11 10:10:40.816335674~2019-05-11 10:26:38.131479341.txt    4.998653441599028  count: 7393  percentage: 0.08804544588414634  node count: 2126  edge count: 2139\n",
      "index_count: 40\n",
      "thr: 2.186913566165521\n",
      "graph_5_11/2019-05-11 10:26:38.131479341~2019-05-11 10:43:01.494767519.txt    5.085277833671213  count: 7704  percentage: 0.04615605828220859  node count: 1840  edge count: 1851\n",
      "index_count: 41\n",
      "thr: 1.9918473637033856\n",
      "graph_5_11/2019-05-11 10:43:01.494767519~2019-05-11 10:58:29.047869392.txt    5.161271809618834  count: 5877  percentage: 0.03930998501712329  node count: 1024  edge count: 1037\n",
      "index_count: 42\n",
      "thr: 1.7059882982850465\n",
      "graph_5_11/2019-05-11 10:58:29.047869392~2019-05-11 11:14:01.491540813.txt    4.165441666798427  count: 7499  percentage: 0.04755352069805195  node count: 1744  edge count: 1755\n",
      "index_count: 43\n",
      "thr: 1.8219616457228667\n",
      "graph_5_11/2019-05-11 11:14:01.491540813~2019-05-11 11:29:31.376280190.txt    4.182049054094559  count: 4968  percentage: 0.053313873626373624  node count: 77  edge count: 86\n",
      "index_count: 44\n",
      "thr: 2.6647013905938683\n",
      "graph_5_11/2019-05-11 11:29:31.376280190~2019-05-11 11:45:00.345862636.txt    4.23473381549505  count: 4644  percentage: 0.11337890625  node count: 123  edge count: 127\n",
      "index_count: 45\n",
      "thr: 1.89621641043241\n",
      "graph_5_11/2019-05-11 11:45:00.345862636~2019-05-11 12:01:12.133236819.txt    4.1704308533759695  count: 5230  percentage: 0.058038884943181816  node count: 85  edge count: 96\n",
      "index_count: 46\n",
      "thr: 1.9380301233633064\n",
      "graph_5_11/2019-05-11 12:01:12.133236819~2019-05-11 12:16:36.422369171.txt    4.1829089733339515  count: 4783  percentage: 0.05912529667721519  node count: 73  edge count: 81\n",
      "index_count: 47\n",
      "thr: 1.9298761863448712\n",
      "graph_5_11/2019-05-11 12:16:36.422369171~2019-05-11 12:32:11.330592128.txt    4.876621612468537  count: 6996  percentage: 0.042434976708074536  node count: 2183  edge count: 2197\n",
      "index_count: 48\n",
      "thr: 1.817757812054127\n",
      "graph_5_11/2019-05-11 12:32:11.330592128~2019-05-11 12:47:47.220351426.txt    4.323147629403026  count: 5218  percentage: 0.04853050595238095  node count: 101  edge count: 112\n",
      "index_count: 49\n",
      "thr: 2.0960448738559565\n",
      "graph_5_11/2019-05-11 12:47:47.220351426~2019-05-11 13:03:23.643575678.txt    4.281646907407474  count: 4590  percentage: 0.06896033653846154  node count: 70  edge count: 79\n",
      "index_count: 50\n",
      "thr: 1.913108829780504\n",
      "graph_5_11/2019-05-11 13:03:23.643575678~2019-05-11 13:18:29.629091674.txt    4.177533676325583  count: 4733  percentage: 0.05925731169871795  node count: 78  edge count: 85\n",
      "index_count: 51\n",
      "thr: 2.2645262074686214\n",
      "graph_5_11/2019-05-11 13:18:29.629091674~2019-05-11 13:33:41.349874830.txt    4.577623873044535  count: 5107  percentage: 0.06649739583333333  node count: 127  edge count: 139\n",
      "index_count: 52\n",
      "thr: 2.240092249039161\n",
      "graph_5_11/2019-05-11 13:33:41.349874830~2019-05-11 13:48:47.890783419.txt    4.248094337713208  count: 4367  percentage: 0.07897497106481481  node count: 93  edge count: 100\n",
      "index_count: 53\n",
      "thr: 3.2421813050855905\n",
      "graph_5_11/2019-05-11 13:48:47.890783419~2019-05-11 14:04:31.519639837.txt    4.197767320301554  count: 3747  percentage: 0.15909476902173914  node count: 46  edge count: 47\n",
      "index_count: 54\n",
      "thr: 2.1295173074641327\n",
      "graph_5_11/2019-05-11 14:04:31.519639837~2019-05-11 14:19:36.223542340.txt    4.100199550684797  count: 4553  percentage: 0.07800507127192982  node count: 65  edge count: 74\n",
      "index_count: 55\n",
      "thr: 3.8656400083023605\n",
      "graph_5_11/2019-05-11 14:19:36.223542340~2019-05-11 14:34:58.512935630.txt    4.749185458398783  count: 2496  percentage: 0.14338235294117646  node count: 45  edge count: 51\n",
      "index_count: 56\n",
      "thr: 2.587080021970578\n",
      "graph_5_11/2019-05-11 14:34:58.512935630~2019-05-11 14:50:01.493772506.txt    4.1722143788612325  count: 4202  percentage: 0.1109058277027027  node count: 76  edge count: 80\n",
      "index_count: 57\n",
      "thr: 2.3116024300317317\n",
      "graph_5_11/2019-05-11 14:50:01.493772506~2019-05-11 15:05:01.505056736.txt    4.143359313403937  count: 4322  percentage: 0.08980219414893617  node count: 62  edge count: 65\n",
      "index_count: 58\n",
      "thr: 3.806632249280189\n",
      "graph_5_11/2019-05-11 15:05:01.505056736~2019-05-11 15:20:31.495771178.txt    4.596881908811005  count: 2685  percentage: 0.15423943014705882  node count: 36  edge count: 40\n",
      "index_count: 59\n",
      "thr: 2.487491067428793\n",
      "graph_5_11/2019-05-11 15:20:31.495771178~2019-05-11 15:37:25.002879746.txt    4.048715617144445  count: 4738  percentage: 0.11285251524390244  node count: 72  edge count: 77\n",
      "index_count: 60\n",
      "thr: 2.977824219989442\n",
      "graph_5_11/2019-05-11 15:37:25.002879746~2019-05-11 15:52:31.494545785.txt    4.0593903579360955  count: 4239  percentage: 0.14784458705357142  node count: 59  edge count: 62\n",
      "index_count: 61\n",
      "thr: 3.1497492448484223\n",
      "graph_5_11/2019-05-11 15:52:31.494545785~2019-05-11 16:08:01.493484725.txt    4.077257435948622  count: 4165  percentage: 0.16947428385416666  node count: 44  edge count: 46\n",
      "index_count: 62\n",
      "thr: 2.414851114403675\n",
      "graph_5_11/2019-05-11 16:08:01.493484725~2019-05-11 16:23:41.450431419.txt    4.126274767378656  count: 4490  percentage: 0.09965376420454546  node count: 64  edge count: 67\n",
      "index_count: 63\n",
      "thr: 3.1668078941293074\n",
      "graph_5_11/2019-05-11 16:23:41.450431419~2019-05-11 16:39:13.198252375.txt    4.0548918663083136  count: 3996  percentage: 0.16966711956521738  node count: 57  edge count: 61\n",
      "index_count: 64\n",
      "thr: 3.3054585727304895\n",
      "graph_5_11/2019-05-11 16:39:13.198252375~2019-05-11 16:55:01.500153909.txt    4.171244279280908  count: 3752  percentage: 0.16654829545454544  node count: 49  edge count: 53\n",
      "index_count: 65\n",
      "thr: 3.327761969996018\n",
      "graph_5_11/2019-05-11 16:55:01.500153909~2019-05-11 17:11:03.959014293.txt    4.482706873449094  count: 3777  percentage: 0.14186448317307693  node count: 51  edge count: 53\n",
      "index_count: 66\n",
      "thr: 4.843420736219901\n",
      "graph_5_11/2019-05-11 17:11:03.959014293~2019-05-11 17:27:33.517836395.txt    6.2215473644617125  count: 656  percentage: 0.05823863636363636  node count: 14  edge count: 16\n",
      "index_count: 67\n",
      "thr: 2.563865169973422\n",
      "graph_5_11/2019-05-11 17:27:33.517836395~2019-05-11 17:43:31.490443808.txt    4.217642411734039  count: 4540  percentage: 0.10813643292682927  node count: 81  edge count: 85\n",
      "index_count: 68\n",
      "thr: 4.028894671007405\n",
      "graph_5_11/2019-05-11 17:43:31.490443808~2019-05-11 17:59:31.493502219.txt    5.280793167042383  count: 1433  percentage: 0.08746337890625  node count: 35  edge count: 38\n",
      "index_count: 69\n",
      "thr: 3.0425250614909536\n",
      "graph_5_11/2019-05-11 17:59:31.493502219~2019-05-11 18:15:44.708305071.txt    4.156446899435559  count: 4614  percentage: 0.15537446120689655  node count: 59  edge count: 60\n",
      "index_count: 70\n",
      "thr: 2.099652486160099\n",
      "graph_5_11/2019-05-11 18:15:44.708305071~2019-05-11 18:32:01.493784231.txt    4.139103817684411  count: 5042  percentage: 0.076934814453125  node count: 83  edge count: 94\n",
      "index_count: 71\n",
      "thr: 2.621568153844621\n",
      "graph_5_11/2019-05-11 18:32:01.493784231~2019-05-11 18:47:13.969095860.txt    4.211052649229476  count: 4223  percentage: 0.1114600929054054  node count: 70  edge count: 74\n",
      "index_count: 72\n",
      "thr: 2.789574850187971\n",
      "graph_5_11/2019-05-11 18:47:13.969095860~2019-05-11 19:03:42.787479327.txt    4.235302227595521  count: 4811  percentage: 0.12697951858108109  node count: 50  edge count: 52\n",
      "index_count: 73\n",
      "thr: 3.646437459794246\n",
      "graph_5_11/2019-05-11 19:03:42.787479327~2019-05-11 19:19:45.328437923.txt    4.494604714842585  count: 2789  percentage: 0.14334909539473684  node count: 41  edge count: 42\n",
      "index_count: 74\n",
      "thr: 3.273772539447637\n",
      "graph_5_11/2019-05-11 19:19:45.328437923~2019-05-11 19:36:04.866440471.txt    4.245575637636483  count: 3743  percentage: 0.15892493206521738  node count: 47  edge count: 54\n",
      "index_count: 75\n",
      "thr: 2.2145142617223326\n",
      "graph_5_11/2019-05-11 19:36:04.866440471~2019-05-11 19:51:40.042976171.txt    4.1726843203396555  count: 4657  percentage: 0.08121163504464286  node count: 76  edge count: 79\n",
      "index_count: 76\n",
      "thr: 2.533929259195453\n",
      "graph_5_11/2019-05-11 19:51:40.042976171~2019-05-11 20:07:24.862800224.txt    4.244012770166247  count: 4381  percentage: 0.10434927591463415  node count: 48  edge count: 51\n",
      "index_count: 77\n",
      "thr: 2.483880553548056\n",
      "graph_5_11/2019-05-11 20:07:24.862800224~2019-05-11 20:24:01.506044420.txt    4.050885528268857  count: 4691  percentage: 0.1090727306547619  node count: 66  edge count: 69\n",
      "index_count: 78\n",
      "thr: 4.68427434249131\n",
      "graph_5_11/2019-05-11 20:24:01.506044420~2019-05-11 20:39:47.303979026.txt    6.149635836168811  count: 666  percentage: 0.059126420454545456  node count: 13  edge count: 16\n",
      "index_count: 79\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "thr: 2.778895749977293\n",
      "graph_5_11/2019-05-11 20:39:47.303979026~2019-05-11 20:55:01.495228602.txt    4.110496993160534  count: 4337  percentage: 0.132354736328125  node count: 57  edge count: 60\n",
      "index_count: 80\n",
      "thr: 4.431741488442784\n",
      "graph_5_11/2019-05-11 20:55:01.495228602~2019-05-11 21:11:31.496595479.txt    6.090614757040044  count: 728  percentage: 0.0546875  node count: 19  edge count: 19\n",
      "index_count: 81\n",
      "thr: 4.724314276007499\n",
      "graph_5_11/2019-05-11 21:11:31.496595479~2019-05-11 21:28:01.492916934.txt    6.325529441354413  count: 637  percentage: 0.05655184659090909  node count: 13  edge count: 15\n",
      "index_count: 82\n",
      "thr: 2.3299606678593996\n",
      "graph_5_11/2019-05-11 21:28:01.492916934~2019-05-11 21:44:43.279039868.txt    4.078378688396778  count: 4756  percentage: 0.09478635204081633  node count: 73  edge count: 77\n",
      "index_count: 83\n",
      "thr: 2.8936515811761954\n",
      "graph_5_11/2019-05-11 21:44:43.279039868~2019-05-11 21:59:49.871208266.txt    4.5920513254882644  count: 6028  percentage: 0.1132061298076923  node count: 1637  edge count: 1641\n",
      "index_count: 84\n",
      "thr: 3.724005855587201\n",
      "graph_5_11/2019-05-11 21:59:49.871208266~2019-05-11 22:15:17.913406650.txt    4.652125140369492  count: 2584  percentage: 0.1401909722222222  node count: 36  edge count: 38\n",
      "index_count: 85\n",
      "thr: 3.293805837590698\n",
      "graph_5_11/2019-05-11 22:15:17.913406650~2019-05-11 22:30:29.105231854.txt    4.2673651658551375  count: 3612  percentage: 0.16033380681818182  node count: 46  edge count: 51\n",
      "index_count: 86\n",
      "thr: 3.2880797208458823\n",
      "graph_5_11/2019-05-11 22:30:29.105231854~2019-05-11 22:45:41.943179151.txt    4.2426733022462315  count: 3211  percentage: 0.14932105654761904  node count: 51  edge count: 54\n",
      "index_count: 87\n",
      "thr: 4.342234024525094\n",
      "graph_5_11/2019-05-11 22:45:41.943179151~2019-05-11 23:02:31.492113855.txt    5.934396377062602  count: 853  percentage: 0.06407752403846154  node count: 12  edge count: 13\n",
      "index_count: 88\n",
      "thr: 2.281007102932297\n",
      "graph_5_11/2019-05-11 23:02:31.492113855~2019-05-11 23:17:43.542872267.txt    4.0623890975215176  count: 4524  percentage: 0.0901626275510204  node count: 67  edge count: 73\n",
      "index_count: 89\n",
      "thr: 2.877059881996555\n",
      "graph_5_11/2019-05-11 23:17:43.542872267~2019-05-11 23:33:01.508230259.txt    4.079819273317874  count: 4271  percentage: 0.14382408405172414  node count: 52  edge count: 57\n",
      "index_count: 90\n",
      "thr: 2.653938356216072\n",
      "graph_5_11/2019-05-11 23:33:01.508230259~2019-05-11 23:48:02.369685328.txt    4.337533778559279  count: 4320  percentage: 0.10817307692307693  node count: 65  edge count: 69\n"
     ]
    }
   ],
   "source": [
    "# Variable names don't change the results\n",
    "\n",
    "# node_IDF=torch.load(\"node_IDF_5_9\")\n",
    "y_data_5_14=[]\n",
    "df_list_5_14=[]\n",
    "# node_set_list=[]\n",
    "history_list_5_14=[]\n",
    "tw_que=[]\n",
    "his_tw={}\n",
    "current_tw={}\n",
    "loss_list_5_14=[]\n",
    "\n",
    "\n",
    "file_path_list=[]\n",
    "file_path=\"graph_5_11/\"\n",
    "file_l=os.listdir(\"graph_5_11/\")\n",
    "for i in file_l:\n",
    "    file_path_list.append(file_path+i)\n",
    "    \n",
    "    \n",
    "index_count=0\n",
    "for f_path in sorted(file_path_list):\n",
    "    f=open(f_path)\n",
    "    edge_loss_list=[]\n",
    "    edge_list=[]\n",
    "    print('index_count:',index_count)\n",
    "    \n",
    "    for line in f:\n",
    "        l=line.strip()\n",
    "        jdata=eval(l)\n",
    "        edge_loss_list.append(jdata['loss'])\n",
    "        edge_list.append([str(jdata['srcmsg']),str(jdata['dstmsg'])])\n",
    "    df_list_5_14.append(pd.DataFrame(edge_loss_list))\n",
    "    count,loss_avg,node_set,edge_set=cal_anomaly_loss(edge_loss_list,edge_list,\"graph_5_14/\")\n",
    "    current_tw['name']=f_path\n",
    "    current_tw['loss']=loss_avg\n",
    "    current_tw['index']=index_count\n",
    "    current_tw['nodeset']=node_set\n",
    "\n",
    "    added_que_flag=False\n",
    "    for hq in history_list_5_14:\n",
    "        for his_tw in hq:\n",
    "            if cal_set_rel(current_tw['nodeset'],his_tw['nodeset'],file_list)!=0 and current_tw['name']!=his_tw['name']:\n",
    "                print(\"history queue:\",his_tw['name'])\n",
    "                hq.append(copy.deepcopy(current_tw))\n",
    "                added_que_flag=True\n",
    "                break\n",
    "            if added_que_flag:\n",
    "                break\n",
    "    if added_que_flag is False:\n",
    "        temp_hq=[copy.deepcopy(current_tw)]\n",
    "        history_list_5_14.append(temp_hq)\n",
    "    index_count+=1\n",
    "    loss_list_5_14.append(loss_avg)\n",
    "    print( f_path,\"  \",loss_avg,\" count:\",count,\" percentage:\",count/len(edge_list),\" node count:\",len(node_set),\" edge count:\",len(edge_set))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['graph_5_11/2019-05-11 00:15:10.585413361~2019-05-11 00:31:01.430200716.txt']\n",
      "5.477715654731948\n",
      "['graph_5_11/2019-05-11 00:46:29.482831031~2019-05-11 01:01:37.064383098.txt']\n",
      "5.119590005644783\n",
      "['graph_5_11/2019-05-11 01:01:37.064383098~2019-05-11 01:16:39.942709627.txt']\n",
      "5.143359333742588\n",
      "['graph_5_11/2019-05-11 01:16:39.942709627~2019-05-11 01:32:01.462298208.txt']\n",
      "5.211801867779716\n",
      "['graph_5_11/2019-05-11 01:32:01.462298208~2019-05-11 01:47:38.109830109.txt']\n",
      "6.128484290728158\n",
      "['graph_5_11/2019-05-11 01:47:38.109830109~2019-05-11 02:03:11.829718951.txt']\n",
      "7.602644764211479\n",
      "['graph_5_11/2019-05-11 02:03:11.829718951~2019-05-11 02:18:49.612834801.txt']\n",
      "5.577765095901761\n",
      "['graph_5_11/2019-05-11 02:18:49.612834801~2019-05-11 02:34:35.963377275.txt']\n",
      "5.2938465188316695\n",
      "['graph_5_11/2019-05-11 02:34:35.963377275~2019-05-11 02:51:01.459395653.txt']\n",
      "5.440255041106367\n",
      "['graph_5_11/2019-05-11 02:51:01.459395653~2019-05-11 03:06:06.971449468.txt']\n",
      "5.101915918542292\n",
      "['graph_5_11/2019-05-11 03:06:06.971449468~2019-05-11 03:22:04.391793517.txt']\n",
      "5.0968968632052825\n",
      "['graph_5_11/2019-05-11 03:22:04.391793517~2019-05-11 03:37:32.924133941.txt']\n",
      "5.115309919337591\n",
      "['graph_5_11/2019-05-11 03:37:32.924133941~2019-05-11 03:52:38.714923518.txt']\n",
      "5.086436751665838\n",
      "['graph_5_11/2019-05-11 03:52:38.714923518~2019-05-11 04:09:01.471666913.txt']\n",
      "5.208142262073009\n",
      "['graph_5_11/2019-05-11 04:09:01.471666913~2019-05-11 04:25:28.350226445.txt']\n",
      "5.210821192646287\n",
      "['graph_5_11/2019-05-11 04:25:28.350226445~2019-05-11 04:41:31.612705711.txt']\n",
      "5.461089675807989\n",
      "['graph_5_11/2019-05-11 04:41:31.612705711~2019-05-11 04:56:49.395636083.txt']\n",
      "5.35056328502464\n",
      "['graph_5_11/2019-05-11 04:56:49.395636083~2019-05-11 05:13:04.898139559.txt']\n",
      "5.574507888764967\n",
      "['graph_5_11/2019-05-11 05:13:04.898139559~2019-05-11 05:29:01.492754751.txt']\n",
      "5.416441831170014\n",
      "['graph_5_11/2019-05-11 05:29:01.492754751~2019-05-11 05:45:26.427321308.txt']\n",
      "5.106894324733832\n",
      "['graph_5_11/2019-05-11 05:45:26.427321308~2019-05-11 06:00:32.541397033.txt']\n",
      "6.636600474047012\n",
      "['graph_5_11/2019-05-11 06:00:32.541397033~2019-05-11 06:16:02.917974906.txt']\n",
      "5.023628586503518\n",
      "['graph_5_11/2019-05-11 06:16:02.917974906~2019-05-11 06:32:01.493579408.txt']\n",
      "5.16881843997147\n",
      "['graph_5_11/2019-05-11 06:32:01.493579408~2019-05-11 06:48:01.495937539.txt']\n",
      "5.342168583225072\n",
      "['graph_5_11/2019-05-11 06:48:01.495937539~2019-05-11 07:03:06.190296071.txt']\n",
      "5.2372418447226154\n",
      "['graph_5_11/2019-05-11 07:03:06.190296071~2019-05-11 07:18:09.159477610.txt']\n",
      "5.57093021343047\n",
      "['graph_5_11/2019-05-11 07:35:01.101406729~2019-05-11 07:50:01.504859344.txt']\n",
      "5.424574391421895\n",
      "['graph_5_11/2019-05-11 07:50:01.504859344~2019-05-11 08:05:27.045713282.txt']\n",
      "5.921228281803395\n",
      "['graph_5_11/2019-05-11 08:05:27.045713282~2019-05-11 08:21:31.505389845.txt']\n",
      "5.134204341131133\n",
      "['graph_5_11/2019-05-11 08:21:31.505389845~2019-05-11 08:37:10.242927755.txt']\n",
      "5.221825739740206\n",
      "['graph_5_11/2019-05-11 08:37:10.242927755~2019-05-11 08:52:11.577068452.txt']\n",
      "5.160441056158214\n",
      "['graph_5_11/2019-05-11 08:52:11.577068452~2019-05-11 09:07:31.497392437.txt']\n",
      "6.535434108100371\n",
      "['graph_5_11/2019-05-11 09:07:31.497392437~2019-05-11 09:23:43.378546037.txt']\n",
      "5.792200498723398\n",
      "['graph_5_11/2019-05-11 09:23:43.378546037~2019-05-11 09:39:28.743031655.txt']\n",
      "5.850633420986232\n",
      "['graph_5_11/2019-05-11 09:39:28.743031655~2019-05-11 09:55:12.543113845.txt']\n",
      "5.395200675844408\n",
      "['graph_5_11/2019-05-11 09:55:12.543113845~2019-05-11 10:10:40.816335674.txt']\n",
      "5.166667220148816\n",
      "['graph_5_11/2019-05-11 10:10:40.816335674~2019-05-11 10:26:38.131479341.txt']\n",
      "5.998653441599028\n",
      "['graph_5_11/2019-05-11 10:26:38.131479341~2019-05-11 10:43:01.494767519.txt']\n",
      "6.085277833671213\n",
      "['graph_5_11/2019-05-11 10:43:01.494767519~2019-05-11 10:58:29.047869392.txt']\n",
      "6.161271809618834\n",
      "['graph_5_11/2019-05-11 10:58:29.047869392~2019-05-11 11:14:01.491540813.txt']\n",
      "5.165441666798427\n",
      "['graph_5_11/2019-05-11 11:14:01.491540813~2019-05-11 11:29:31.376280190.txt']\n",
      "5.182049054094559\n",
      "['graph_5_11/2019-05-11 11:29:31.376280190~2019-05-11 11:45:00.345862636.txt']\n",
      "5.23473381549505\n",
      "['graph_5_11/2019-05-11 11:45:00.345862636~2019-05-11 12:01:12.133236819.txt']\n",
      "5.1704308533759695\n",
      "['graph_5_11/2019-05-11 12:01:12.133236819~2019-05-11 12:16:36.422369171.txt']\n",
      "5.1829089733339515\n",
      "['graph_5_11/2019-05-11 12:16:36.422369171~2019-05-11 12:32:11.330592128.txt']\n",
      "5.876621612468537\n",
      "['graph_5_11/2019-05-11 12:32:11.330592128~2019-05-11 12:47:47.220351426.txt']\n",
      "5.323147629403026\n",
      "['graph_5_11/2019-05-11 12:47:47.220351426~2019-05-11 13:03:23.643575678.txt']\n",
      "5.281646907407474\n",
      "['graph_5_11/2019-05-11 13:03:23.643575678~2019-05-11 13:18:29.629091674.txt']\n",
      "5.177533676325583\n",
      "['graph_5_11/2019-05-11 13:18:29.629091674~2019-05-11 13:33:41.349874830.txt']\n",
      "5.577623873044535\n",
      "['graph_5_11/2019-05-11 13:33:41.349874830~2019-05-11 13:48:47.890783419.txt']\n",
      "5.248094337713208\n",
      "['graph_5_11/2019-05-11 13:48:47.890783419~2019-05-11 14:04:31.519639837.txt']\n",
      "5.197767320301554\n",
      "['graph_5_11/2019-05-11 14:04:31.519639837~2019-05-11 14:19:36.223542340.txt']\n",
      "5.100199550684797\n",
      "['graph_5_11/2019-05-11 14:19:36.223542340~2019-05-11 14:34:58.512935630.txt']\n",
      "5.749185458398783\n",
      "['graph_5_11/2019-05-11 14:34:58.512935630~2019-05-11 14:50:01.493772506.txt']\n",
      "5.1722143788612325\n",
      "['graph_5_11/2019-05-11 14:50:01.493772506~2019-05-11 15:05:01.505056736.txt']\n",
      "5.143359313403937\n",
      "['graph_5_11/2019-05-11 15:05:01.505056736~2019-05-11 15:20:31.495771178.txt']\n",
      "5.596881908811005\n",
      "['graph_5_11/2019-05-11 15:20:31.495771178~2019-05-11 15:37:25.002879746.txt']\n",
      "5.048715617144445\n",
      "['graph_5_11/2019-05-11 15:37:25.002879746~2019-05-11 15:52:31.494545785.txt']\n",
      "5.0593903579360955\n",
      "['graph_5_11/2019-05-11 15:52:31.494545785~2019-05-11 16:08:01.493484725.txt']\n",
      "5.077257435948622\n",
      "['graph_5_11/2019-05-11 16:08:01.493484725~2019-05-11 16:23:41.450431419.txt']\n",
      "5.126274767378656\n",
      "['graph_5_11/2019-05-11 16:23:41.450431419~2019-05-11 16:39:13.198252375.txt']\n",
      "5.0548918663083136\n",
      "['graph_5_11/2019-05-11 16:39:13.198252375~2019-05-11 16:55:01.500153909.txt']\n",
      "5.171244279280908\n",
      "['graph_5_11/2019-05-11 16:55:01.500153909~2019-05-11 17:11:03.959014293.txt']\n",
      "5.482706873449094\n",
      "['graph_5_11/2019-05-11 17:11:03.959014293~2019-05-11 17:27:33.517836395.txt']\n",
      "7.2215473644617125\n",
      "['graph_5_11/2019-05-11 17:27:33.517836395~2019-05-11 17:43:31.490443808.txt']\n",
      "5.217642411734039\n",
      "['graph_5_11/2019-05-11 17:43:31.490443808~2019-05-11 17:59:31.493502219.txt']\n",
      "6.280793167042383\n",
      "['graph_5_11/2019-05-11 17:59:31.493502219~2019-05-11 18:15:44.708305071.txt']\n",
      "5.156446899435559\n",
      "['graph_5_11/2019-05-11 18:15:44.708305071~2019-05-11 18:32:01.493784231.txt']\n",
      "5.139103817684411\n",
      "['graph_5_11/2019-05-11 18:32:01.493784231~2019-05-11 18:47:13.969095860.txt']\n",
      "5.211052649229476\n",
      "['graph_5_11/2019-05-11 18:47:13.969095860~2019-05-11 19:03:42.787479327.txt']\n",
      "5.235302227595521\n",
      "['graph_5_11/2019-05-11 19:03:42.787479327~2019-05-11 19:19:45.328437923.txt']\n",
      "5.494604714842585\n",
      "['graph_5_11/2019-05-11 19:19:45.328437923~2019-05-11 19:36:04.866440471.txt']\n",
      "5.245575637636483\n",
      "['graph_5_11/2019-05-11 19:36:04.866440471~2019-05-11 19:51:40.042976171.txt']\n",
      "5.1726843203396555\n",
      "['graph_5_11/2019-05-11 19:51:40.042976171~2019-05-11 20:07:24.862800224.txt']\n",
      "5.244012770166247\n",
      "['graph_5_11/2019-05-11 20:07:24.862800224~2019-05-11 20:24:01.506044420.txt']\n",
      "5.050885528268857\n",
      "['graph_5_11/2019-05-11 20:24:01.506044420~2019-05-11 20:39:47.303979026.txt']\n",
      "7.149635836168811\n",
      "['graph_5_11/2019-05-11 20:39:47.303979026~2019-05-11 20:55:01.495228602.txt']\n",
      "5.110496993160534\n",
      "['graph_5_11/2019-05-11 20:55:01.495228602~2019-05-11 21:11:31.496595479.txt']\n",
      "7.090614757040044\n",
      "['graph_5_11/2019-05-11 21:11:31.496595479~2019-05-11 21:28:01.492916934.txt']\n",
      "7.325529441354413\n",
      "['graph_5_11/2019-05-11 21:28:01.492916934~2019-05-11 21:44:43.279039868.txt']\n",
      "5.078378688396778\n",
      "['graph_5_11/2019-05-11 21:44:43.279039868~2019-05-11 21:59:49.871208266.txt']\n",
      "5.5920513254882644\n",
      "['graph_5_11/2019-05-11 21:59:49.871208266~2019-05-11 22:15:17.913406650.txt']\n",
      "5.652125140369492\n",
      "['graph_5_11/2019-05-11 22:15:17.913406650~2019-05-11 22:30:29.105231854.txt']\n",
      "5.2673651658551375\n",
      "['graph_5_11/2019-05-11 22:30:29.105231854~2019-05-11 22:45:41.943179151.txt']\n",
      "5.2426733022462315\n",
      "['graph_5_11/2019-05-11 22:45:41.943179151~2019-05-11 23:02:31.492113855.txt']\n",
      "6.934396377062602\n",
      "['graph_5_11/2019-05-11 23:02:31.492113855~2019-05-11 23:17:43.542872267.txt']\n",
      "5.0623890975215176\n",
      "['graph_5_11/2019-05-11 23:17:43.542872267~2019-05-11 23:33:01.508230259.txt']\n",
      "5.079819273317874\n",
      "['graph_5_11/2019-05-11 23:33:01.508230259~2019-05-11 23:48:02.369685328.txt']\n",
      "5.337533778559279\n"
     ]
    }
   ],
   "source": [
    "name_list=[]\n",
    "for hl in history_list_5_14:\n",
    "    loss_count=0\n",
    "    for hq in hl:\n",
    "        if loss_count==0:\n",
    "            loss_count=(loss_count+1)*(hq['loss']+1)\n",
    "        else:\n",
    "            loss_count=(loss_count)*(hq['loss']+1)\n",
    "#     name_list=[]\n",
    "    if loss_count>5:\n",
    "        name_list=[]\n",
    "        for i in hl:\n",
    "            name_list.append(i['name']) \n",
    "        print(name_list)\n",
    "        print(loss_count)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 5-14"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "index_count: 0\n",
      "thr: 1.2592084108895936\n",
      "graph_5_14/2019-05-14 00:00:00.216652068~2019-05-14 00:15:02.152576344.txt    3.6231953809918127  count: 5935  percentage: 0.03237932087988827  node count: 306  edge count: 509\n",
      "index_count: 1\n",
      "thr: 1.994229076406853\n",
      "graph_5_14/2019-05-14 00:15:02.152576344~2019-05-14 00:30:52.456495816.txt    4.082461574633764  count: 5230  percentage: 0.06633015422077922  node count: 84  edge count: 93\n",
      "index_count: 2\n",
      "thr: 1.8691974170643886\n",
      "graph_5_14/2019-05-14 00:30:52.456495816~2019-05-14 00:46:31.488675323.txt    4.305617655349725  count: 5007  percentage: 0.05373240041208791  node count: 119  edge count: 129\n",
      "index_count: 3\n",
      "thr: 1.5131819994016185\n",
      "graph_5_14/2019-05-14 00:46:31.488675323~2019-05-14 01:02:22.766494572.txt    4.29130935320164  count: 5161  percentage: 0.03876953125  node count: 109  edge count: 121\n",
      "index_count: 4\n",
      "thr: 1.3654904935329784\n",
      "graph_5_14/2019-05-14 01:02:22.766494572~2019-05-14 01:18:47.800927242.txt    4.171355080096775  count: 5024  percentage: 0.03383620689655172  node count: 160  edge count: 168\n",
      "index_count: 5\n",
      "thr: 1.824870794149769\n",
      "graph_5_14/2019-05-14 01:18:47.800927242~2019-05-14 01:33:57.109874818.txt    4.265906363812821  count: 5129  percentage: 0.050087890625  node count: 165  edge count: 179\n",
      "index_count: 6\n",
      "thr: 1.0480100440706783\n",
      "graph_5_14/2019-05-14 01:33:57.109874818~2019-05-14 01:49:42.711286391.txt    3.8330079138392783  count: 6284  percentage: 0.021761414007092198  node count: 147  edge count: 167\n",
      "index_count: 7\n",
      "thr: 1.0916583205795718\n",
      "graph_5_14/2019-05-14 01:49:42.711286391~2019-05-14 02:04:42.847148244.txt    3.8978413828822207  count: 5462  percentage: 0.02269780585106383  node count: 299  edge count: 318\n",
      "index_count: 8\n",
      "thr: 2.268038164727402\n",
      "graph_5_14/2019-05-14 02:04:42.847148244~2019-05-14 02:21:17.881023437.txt    4.103662085093531  count: 5098  percentage: 0.08890206473214286  node count: 77  edge count: 81\n",
      "index_count: 9\n",
      "thr: 1.4225734990244239\n",
      "graph_5_14/2019-05-14 02:21:17.881023437~2019-05-14 02:37:08.796215519.txt    3.859354054137201  count: 6197  percentage: 0.0392971286525974  node count: 1089  edge count: 1104\n",
      "index_count: 10\n",
      "thr: 0.9887701255519733\n",
      "graph_5_14/2019-05-14 02:37:08.796215519~2019-05-14 02:53:02.686777403.txt    4.008120422724912  count: 5182  percentage: 0.019168738162878788  node count: 112  edge count: 129\n",
      "index_count: 11\n",
      "thr: 1.9318936961284727\n",
      "graph_5_14/2019-05-14 02:53:02.686777403~2019-05-14 03:08:06.039823042.txt    4.757089458821669  count: 6757  percentage: 0.044888658588435375  node count: 1303  edge count: 1317\n",
      "index_count: 12\n",
      "thr: 2.1130244928895854\n",
      "graph_5_14/2019-05-14 03:08:06.039823042~2019-05-14 03:24:24.125824282.txt    4.129458770518141  count: 4813  percentage: 0.07580960181451613  node count: 80  edge count: 86\n",
      "index_count: 13\n",
      "thr: 2.418810223651454\n",
      "graph_5_14/2019-05-14 03:24:24.125824282~2019-05-14 03:40:31.492266909.txt    4.278939917828742  count: 4928  percentage: 0.08912037037037036  node count: 93  edge count: 101\n",
      "index_count: 14\n",
      "thr: 1.780197647019195\n",
      "graph_5_14/2019-05-14 03:40:31.492266909~2019-05-14 03:55:39.463370919.txt    4.232263322124164  count: 5353  percentage: 0.048403139467592594  node count: 157  edge count: 171\n",
      "index_count: 15\n",
      "thr: 1.1683865599919634\n",
      "graph_5_14/2019-05-14 03:55:39.463370919~2019-05-14 04:11:20.402783947.txt    4.042854097992325  count: 5422  percentage: 0.024177725456621006  node count: 109  edge count: 123\n",
      "index_count: 16\n",
      "thr: 1.6950091724193288\n",
      "graph_5_14/2019-05-14 04:11:20.402783947~2019-05-14 04:27:29.028367610.txt    4.142779797653804  count: 5199  percentage: 0.04701063368055555  node count: 76  edge count: 87\n",
      "index_count: 17\n",
      "thr: 1.7978872841823952\n",
      "graph_5_14/2019-05-14 04:27:29.028367610~2019-05-14 04:42:31.507049782.txt    4.122557098065369  count: 4699  percentage: 0.05736083984375  node count: 111  edge count: 122\n",
      "index_count: 18\n",
      "thr: 2.385620442282621\n",
      "graph_5_14/2019-05-14 04:42:31.507049782~2019-05-14 04:57:54.101068941.txt    4.132373259233147  count: 4578  percentage: 0.0931396484375  node count: 69  edge count: 74\n",
      "index_count: 19\n",
      "thr: 1.0931547404458244\n",
      "graph_5_14/2019-05-14 04:57:54.101068941~2019-05-14 05:13:31.492618479.txt    4.082022124614745  count: 5276  percentage: 0.021648503151260504  node count: 105  edge count: 123\n",
      "index_count: 20\n",
      "thr: 1.9045211082111868\n",
      "graph_5_14/2019-05-14 05:13:31.492618479~2019-05-14 05:29:31.505968490.txt    4.28550730643053  count: 5151  percentage: 0.056519926264044944  node count: 75  edge count: 82\n",
      "index_count: 21\n",
      "thr: 1.5811326683991282\n",
      "graph_5_14/2019-05-14 05:29:31.505968490~2019-05-14 05:44:42.157151223.txt    4.492065250118332  count: 6077  percentage: 0.037091064453125  node count: 1106  edge count: 1119\n",
      "index_count: 22\n",
      "thr: 2.429907125398527\n",
      "graph_5_14/2019-05-14 05:44:42.157151223~2019-05-14 05:59:43.139781502.txt    4.314022071210375  count: 4495  percentage: 0.09339677526595745  node count: 77  edge count: 82\n",
      "index_count: 23\n",
      "thr: 2.054088467220094\n",
      "graph_5_14/2019-05-14 05:59:43.139781502~2019-05-14 06:14:50.863134060.txt    4.531831805006094  count: 6036  percentage: 0.0589453125  node count: 1196  edge count: 1205\n",
      "index_count: 24\n",
      "thr: 1.7039365877486445\n",
      "graph_5_14/2019-05-14 06:14:50.863134060~2019-05-14 06:30:25.403853123.txt    4.0952793483347625  count: 5305  percentage: 0.048417421144859814  node count: 92  edge count: 102\n",
      "index_count: 25\n",
      "thr: 1.9217318981311848\n",
      "graph_5_14/2019-05-14 06:30:25.403853123~2019-05-14 06:45:43.292845666.txt    4.163602799383877  count: 4902  percentage: 0.060596321202531646  node count: 151  edge count: 168\n",
      "index_count: 26\n",
      "thr: 1.2796251999898316\n",
      "graph_5_14/2019-05-14 06:45:43.292845666~2019-05-14 07:00:48.956786874.txt    4.14562795271002  count: 4799  percentage: 0.029661540743670885  node count: 107  edge count: 115\n",
      "index_count: 27\n",
      "thr: 1.8582419957446021\n",
      "graph_5_14/2019-05-14 07:00:48.956786874~2019-05-14 07:15:55.106970028.txt    4.257735407114174  count: 4953  percentage: 0.05496493252840909  node count: 78  edge count: 87\n",
      "index_count: 28\n",
      "thr: 1.8567617230097757\n",
      "graph_5_14/2019-05-14 07:15:55.106970028~2019-05-14 07:31:06.351388922.txt    4.280392773537152  count: 4586  percentage: 0.051477191091954026  node count: 85  edge count: 97\n",
      "index_count: 29\n",
      "thr: 2.334542425917821\n",
      "graph_5_14/2019-05-14 07:31:06.351388922~2019-05-14 07:46:06.406187653.txt    4.671229690674601  count: 8167  percentage: 0.06182624757751938  node count: 354  edge count: 423\n",
      "index_count: 30\n",
      "thr: 2.3977067424914105\n",
      "graph_5_14/2019-05-14 07:46:06.406187653~2019-05-14 08:01:28.100458703.txt    4.557968600944624  count: 17351  percentage: 0.07060139973958333  node count: 831  edge count: 858\n",
      "index_count: 31\n",
      "thr: 2.8952166676857036\n",
      "graph_5_14/2019-05-14 08:01:28.100458703~2019-05-14 08:16:28.839199678.txt    5.639525978989724  count: 8037  percentage: 0.06884765625  node count: 329  edge count: 448\n",
      "index_count: 32\n",
      "thr: 10.014760251255101\n",
      "graph_5_14/2019-05-14 08:16:28.839199678~2019-05-14 08:31:32.729512360.txt    10.940246267743202  count: 22849  percentage: 0.23003584085051546  node count: 32  edge count: 35\n",
      "index_count: 33\n",
      "thr: 1.0771054048960198\n",
      "graph_5_14/2019-05-14 08:31:32.729512360~2019-05-14 08:46:44.052873581.txt    4.043315948830002  count: 5980  percentage: 0.020562830105633804  node count: 144  edge count: 177\n",
      "index_count: 34\n",
      "thr: 2.019334196772008\n",
      "graph_5_14/2019-05-14 08:46:44.052873581~2019-05-14 09:02:14.558261420.txt    4.248788999284202  count: 4683  percentage: 0.06441186179577464  node count: 79  edge count: 85\n",
      "index_count: 35\n",
      "thr: 3.4133560649141117\n",
      "graph_5_14/2019-05-14 09:02:14.558261420~2019-05-14 09:17:20.971655668.txt    7.502051451822775  count: 10456  percentage: 0.05489751344086022  node count: 569  edge count: 897\n",
      "index_count: 36\n",
      "thr: 10.62110869760639\n",
      "graph_5_14/2019-05-14 09:17:20.971655668~2019-05-14 09:32:31.497798481.txt    11.262087378474261  count: 49012  percentage: 0.23347942073170733  node count: 75  edge count: 77\n",
      "index_count: 37\n",
      "thr: 2.218118612082949\n",
      "graph_5_14/2019-05-14 09:32:31.497798481~2019-05-14 09:49:09.590528813.txt    4.266116098415546  count: 5583  percentage: 0.07367768158783784  node count: 128  edge count: 145\n",
      "index_count: 38\n",
      "thr: 2.136361389708566\n",
      "graph_5_14/2019-05-14 09:49:09.590528813~2019-05-14 10:05:01.487422951.txt    4.2399187337617255  count: 5158  percentage: 0.06900149828767123  node count: 159  edge count: 234\n",
      "index_count: 39\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "thr: 2.2617071670140474\n",
      "graph_5_14/2019-05-14 10:05:01.487422951~2019-05-14 10:21:01.484905000.txt    4.320455895215109  count: 4545  percentage: 0.07522841631355932  node count: 115  edge count: 132\n",
      "index_count: 40\n",
      "thr: 1.831871705913167\n",
      "graph_5_14/2019-05-14 10:21:01.484905000~2019-05-14 10:37:26.048664593.txt    4.231813785616167  count: 5539  percentage: 0.05008499710648148  node count: 84  edge count: 98\n",
      "index_count: 41\n",
      "thr: 2.090339179133271\n",
      "graph_5_14/2019-05-14 10:37:26.048664593~2019-05-14 10:53:01.494421034.txt    4.237315300724239  count: 4838  percentage: 0.07051655783582089  node count: 73  edge count: 84\n",
      "index_count: 42\n",
      "thr: 1.6402203750954776\n",
      "graph_5_14/2019-05-14 10:53:01.494421034~2019-05-14 11:08:27.055236406.txt    4.218363649633296  count: 5290  percentage: 0.042000127032520325  node count: 73  edge count: 86\n",
      "index_count: 43\n",
      "thr: 1.5681102196196846\n",
      "graph_5_14/2019-05-14 11:08:27.055236406~2019-05-14 11:24:01.496118837.txt    4.284522978199992  count: 3812  percentage: 0.036496629901960786  node count: 244  edge count: 291\n",
      "index_count: 44\n",
      "thr: 1.4979275813322526\n",
      "graph_5_14/2019-05-14 11:24:01.496118837~2019-05-14 11:40:15.252528842.txt    4.663316161815937  count: 1885  percentage: 0.025927046654929578  node count: 172  edge count: 194\n",
      "index_count: 45\n",
      "thr: 1.5115760195334529\n",
      "graph_5_14/2019-05-14 11:40:15.252528842~2019-05-14 11:55:25.711738425.txt    4.87494951524857  count: 2492  percentage: 0.025616776315789475  node count: 559  edge count: 568\n",
      "index_count: 46\n",
      "thr: 1.1647212000990412\n",
      "graph_5_14/2019-05-14 11:55:25.711738425~2019-05-14 12:10:32.440531011.txt    4.116353322399987  count: 2790  percentage: 0.019053212412587412  node count: 245  edge count: 273\n",
      "index_count: 47\n",
      "thr: 1.4601840015029999\n",
      "graph_5_14/2019-05-14 12:10:32.440531011~2019-05-14 12:26:47.026847931.txt    4.816707046093789  count: 1735  percentage: 0.023863886443661973  node count: 158  edge count: 170\n",
      "index_count: 48\n",
      "thr: 0.7052887796729578\n",
      "graph_5_14/2019-05-14 12:26:47.026847931~2019-05-14 12:43:01.495215198.txt    1.2921861487042174  count: 31104  percentage: 0.04278169014084507  node count: 293  edge count: 350\n",
      "index_count: 49\n",
      "thr: 1.3389114130537256\n",
      "graph_5_14/2019-05-14 12:43:01.495215198~2019-05-14 12:59:29.343065601.txt    4.982315398648172  count: 1497  percentage: 0.020590338908450703  node count: 129  edge count: 137\n",
      "index_count: 50\n",
      "thr: 1.1540534665028979\n",
      "graph_5_14/2019-05-14 12:59:29.343065601~2019-05-14 13:14:36.494846495.txt    4.503410371839391  count: 1956  percentage: 0.016610054347826086  node count: 96  edge count: 108\n",
      "index_count: 51\n",
      "thr: 0.8895762806993408\n",
      "graph_5_14/2019-05-14 13:14:36.494846495~2019-05-14 13:31:01.488594793.txt    3.025238572603051  count: 4212  percentage: 0.01904296875  node count: 127  edge count: 158\n",
      "index_count: 52\n",
      "thr: 1.0893975286325317\n",
      "graph_5_14/2019-05-14 13:31:01.488594793~2019-05-14 13:46:56.649368141.txt    4.060751471451377  count: 2591  percentage: 0.016981700922818792  node count: 110  edge count: 126\n",
      "index_count: 53\n",
      "thr: 0.8067034633140282\n",
      "graph_5_14/2019-05-14 13:46:56.649368141~2019-05-14 14:01:56.861865565.txt    2.891690561546732  count: 3258  percentage: 0.0146619383640553  node count: 99  edge count: 125\n",
      "index_count: 54\n",
      "thr: 0.6514465384092096\n",
      "graph_5_14/2019-05-14 14:01:56.861865565~2019-05-14 14:18:12.441876858.txt    1.0823085686629954  count: 23566  percentage: 0.05724793998756219  node count: 123  edge count: 157\n",
      "index_count: 55\n",
      "thr: 1.443053927523655\n",
      "graph_5_14/2019-05-14 14:18:12.441876858~2019-05-14 14:33:35.665615598.txt    4.6872912702633345  count: 1831  percentage: 0.022924178685897436  node count: 84  edge count: 95\n",
      "index_count: 56\n",
      "thr: 1.051036528917456\n",
      "graph_5_14/2019-05-14 14:33:35.665615598~2019-05-14 14:49:05.595227210.txt    3.9642004311360695  count: 2592  percentage: 0.01622596153846154  node count: 104  edge count: 132\n",
      "index_count: 57\n",
      "thr: 0.7584294018148794\n",
      "graph_5_14/2019-05-14 14:49:05.595227210~2019-05-14 15:04:31.495739830.txt    3.1076353297138355  count: 2053  percentage: 0.012689131724683545  node count: 83  edge count: 101\n",
      "index_count: 58\n",
      "thr: 0.6837104583261381\n",
      "graph_5_14/2019-05-14 15:04:31.495739830~2019-05-14 15:19:40.210880344.txt    1.4152893522304586  count: 10578  percentage: 0.03501721398305085  node count: 101  edge count: 121\n",
      "index_count: 59\n",
      "thr: 0.8604609474862649\n",
      "graph_5_14/2019-05-14 15:19:40.210880344~2019-05-14 15:35:01.495871430.txt    3.0973138690116535  count: 2938  percentage: 0.015342997994652406  node count: 91  edge count: 118\n",
      "index_count: 60\n",
      "thr: 1.1804403748857457\n",
      "graph_5_14/2019-05-14 15:35:01.495871430~2019-05-14 15:50:01.496409854.txt    4.341917683021165  count: 2048  percentage: 0.017391304347826087  node count: 98  edge count: 117\n",
      "index_count: 61\n",
      "thr: 1.2182732749953653\n",
      "graph_5_14/2019-05-14 15:50:01.496409854~2019-05-14 16:07:01.495577354.txt    4.6528043948946785  count: 1977  percentage: 0.01804358936915888  node count: 85  edge count: 99\n",
      "index_count: 62\n",
      "thr: 0.830311307699588\n",
      "graph_5_14/2019-05-14 16:07:01.495577354~2019-05-14 16:22:09.008166964.txt    3.24688799963328  count: 2943  percentage: 0.013620964158767773  node count: 107  edge count: 128\n",
      "index_count: 63\n",
      "thr: 0.779329741128631\n",
      "graph_5_14/2019-05-14 16:22:09.008166964~2019-05-14 16:37:48.629717740.txt    2.3264679877055174  count: 4325  percentage: 0.01992279628537736  node count: 94  edge count: 116\n",
      "index_count: 64\n",
      "thr: 0.7919324584629348\n",
      "graph_5_14/2019-05-14 16:37:48.629717740~2019-05-14 16:52:56.416852310.txt    3.01308348981333  count: 2310  percentage: 0.014368531050955414  node count: 77  edge count: 94\n",
      "index_count: 65\n",
      "thr: 1.3059135950462295\n",
      "graph_5_14/2019-05-14 16:52:56.416852310~2019-05-14 17:08:03.416037709.txt    4.8035042571669795  count: 1627  percentage: 0.02090614720394737  node count: 77  edge count: 86\n",
      "index_count: 66\n",
      "thr: 0.7584903968973282\n",
      "graph_5_14/2019-05-14 17:08:03.416037709~2019-05-14 17:23:18.956163567.txt    1.7843937946414286  count: 7482  percentage: 0.0283203125  node count: 115  edge count: 141\n",
      "index_count: 67\n",
      "thr: 0.7714991575402559\n",
      "graph_5_14/2019-05-14 17:23:18.956163567~2019-05-14 17:39:05.176280359.txt    1.8749125725016376  count: 6977  percentage: 0.02399111465669014  node count: 102  edge count: 129\n",
      "index_count: 68\n",
      "thr: 0.8652486917872656\n",
      "graph_5_14/2019-05-14 17:39:05.176280359~2019-05-14 17:55:18.763900563.txt    5.177010889975002  count: 1534  percentage: 0.008864182692307692  node count: 77  edge count: 90\n",
      "index_count: 69\n",
      "thr: 1.2039537480266995\n",
      "graph_5_14/2019-05-14 17:55:18.763900563~2019-05-14 18:10:19.195011436.txt    3.991335388680243  count: 2479  percentage: 0.021051290760869566  node count: 87  edge count: 100\n",
      "index_count: 70\n",
      "thr: 1.1227632189762493\n",
      "graph_5_14/2019-05-14 18:10:19.195011436~2019-05-14 18:25:19.291228993.txt    4.296063451017712  count: 2272  percentage: 0.014991554054054054  node count: 153  edge count: 174\n",
      "index_count: 71\n",
      "thr: 1.1432650439095968\n",
      "graph_5_14/2019-05-14 18:25:19.291228993~2019-05-14 18:40:21.201780869.txt    3.6770240626571034  count: 2830  percentage: 0.020936908143939392  node count: 96  edge count: 117\n",
      "index_count: 72\n",
      "thr: 0.9370448757807008\n",
      "graph_5_14/2019-05-14 18:40:21.201780869~2019-05-14 18:56:52.129475445.txt    3.714013154670404  count: 3029  percentage: 0.013030871420704845  node count: 98  edge count: 128\n",
      "index_count: 73\n",
      "thr: 1.2729339982584658\n",
      "graph_5_14/2019-05-14 18:56:52.129475445~2019-05-14 19:12:10.712408509.txt    3.4308700033176978  count: 3328  percentage: 0.03494623655913978  node count: 76  edge count: 94\n",
      "index_count: 74\n",
      "thr: 1.568456277473922\n",
      "graph_5_14/2019-05-14 19:12:10.712408509~2019-05-14 19:28:38.128423572.txt    4.931230463785519  count: 1313  percentage: 0.027874490489130436  node count: 60  edge count: 67\n",
      "index_count: 75\n",
      "thr: 1.0542831808069502\n",
      "graph_5_14/2019-05-14 19:28:38.128423572~2019-05-14 19:45:01.500731472.txt    4.499095566720369  count: 1992  percentage: 0.01296875  node count: 75  edge count: 93\n",
      "index_count: 76\n",
      "thr: 0.9043434163582214\n",
      "graph_5_14/2019-05-14 19:45:01.500731472~2019-05-14 20:00:01.564775961.txt    3.441789994565138  count: 3034  percentage: 0.013780886627906977  node count: 99  edge count: 126\n",
      "index_count: 77\n",
      "thr: 1.0789057133345428\n",
      "graph_5_14/2019-05-14 20:00:01.564775961~2019-05-14 20:15:31.498565817.txt    4.8164832131405655  count: 2306  percentage: 0.012238875679347826  node count: 97  edge count: 126\n",
      "index_count: 78\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "thr: 0.8725770575913993\n",
      "graph_5_14/2019-05-14 20:15:31.498565817~2019-05-14 20:30:39.905147822.txt    3.8577443106090605  count: 1990  percentage: 0.012785259046052632  node count: 78  edge count: 95\n",
      "index_count: 79\n",
      "thr: 1.3608206456747007\n",
      "graph_5_14/2019-05-14 20:30:39.905147822~2019-05-14 20:48:29.853305652.txt    4.744643823588719  count: 1938  percentage: 0.021506569602272728  node count: 68  edge count: 86\n",
      "index_count: 80\n",
      "thr: 1.3903042193363457\n",
      "graph_5_14/2019-05-14 20:48:29.853305652~2019-05-14 21:03:35.529877137.txt    4.544192067608509  count: 1923  percentage: 0.02470960115131579  node count: 62  edge count: 72\n",
      "index_count: 81\n",
      "thr: 0.8200967635516044\n",
      "graph_5_14/2019-05-14 21:03:35.529877137~2019-05-14 21:19:23.539915401.txt    2.9361406637392427  count: 3346  percentage: 0.015559895833333334  node count: 85  edge count: 111\n",
      "index_count: 82\n",
      "thr: 1.2842951221115098\n",
      "graph_5_14/2019-05-14 21:19:23.539915401~2019-05-14 21:35:16.383991146.txt    4.873076716986831  count: 1656  percentage: 0.01796875  node count: 89  edge count: 103\n",
      "index_count: 83\n",
      "thr: 1.1388252045866958\n",
      "graph_5_14/2019-05-14 21:35:16.383991146~2019-05-14 21:52:04.868022874.txt    4.571803925320478  count: 2156  percentage: 0.016578494094488187  node count: 82  edge count: 104\n",
      "index_count: 84\n",
      "thr: 0.9260638362356568\n",
      "graph_5_14/2019-05-14 21:52:04.868022874~2019-05-14 22:08:01.492103293.txt    4.3141664888411135  count: 1896  percentage: 0.011793391719745224  node count: 71  edge count: 93\n",
      "index_count: 85\n",
      "thr: 1.286061625911985\n",
      "graph_5_14/2019-05-14 22:08:01.492103293~2019-05-14 22:24:09.949262623.txt    4.435270211384725  count: 1353  percentage: 0.022780845905172414  node count: 66  edge count: 75\n",
      "index_count: 86\n",
      "thr: 0.7703716752406611\n",
      "graph_5_14/2019-05-14 22:24:09.949262623~2019-05-14 22:39:18.367975095.txt    2.6570153283073723  count: 3460  percentage: 0.015789281542056076  node count: 71  edge count: 89\n",
      "index_count: 87\n",
      "thr: 0.8003077319076264\n",
      "graph_5_14/2019-05-14 22:39:18.367975095~2019-05-14 22:54:58.932966824.txt    3.142452169876847  count: 2524  percentage: 0.013323479729729729  node count: 76  edge count: 99\n",
      "index_count: 88\n",
      "thr: 1.4074439515351942\n",
      "graph_5_14/2019-05-14 22:54:58.932966824~2019-05-14 23:11:08.033781569.txt    4.815308932927603  count: 1746  percentage: 0.021050347222222224  node count: 68  edge count: 79\n",
      "index_count: 89\n",
      "thr: 1.4101664525345625\n",
      "graph_5_14/2019-05-14 23:11:08.033781569~2019-05-14 23:27:10.374817359.txt    4.769489413291909  count: 1720  percentage: 0.02099609375  node count: 70  edge count: 83\n",
      "index_count: 90\n",
      "thr: 1.8702866211118416\n",
      "graph_5_14/2019-05-14 23:27:10.374817359~2019-05-14 23:42:22.657126844.txt    5.491022228233276  count: 1240  percentage: 0.03186677631578947  node count: 52  edge count: 62\n",
      "index_count: 91\n",
      "thr: 1.7785586926195256\n",
      "graph_5_14/2019-05-14 23:42:22.657126844~2019-05-14 23:57:53.548510363.txt    5.143872813535226  count: 1705  percentage: 0.0302734375  node count: 76  edge count: 87\n"
     ]
    }
   ],
   "source": [
    "# 5-14\n",
    "\n",
    "# node_IDF=torch.load(\"node_IDF_5_9\")\n",
    "y_data_5_14=[]\n",
    "df_list_5_14=[]\n",
    "# node_set_list=[]\n",
    "history_list_5_14=[]\n",
    "tw_que=[]\n",
    "his_tw={}\n",
    "current_tw={}\n",
    "loss_list_5_14=[]\n",
    "\n",
    "\n",
    "file_path_list=[]\n",
    "file_path=\"graph_5_14/\"\n",
    "file_l=os.listdir(\"graph_5_14/\")\n",
    "for i in file_l:\n",
    "    file_path_list.append(file_path+i)\n",
    "    \n",
    "    \n",
    "index_count=0\n",
    "for f_path in sorted(file_path_list):\n",
    "    f=open(f_path)\n",
    "    edge_loss_list=[]\n",
    "    edge_list=[]\n",
    "    print('index_count:',index_count)\n",
    "    \n",
    "    for line in f:\n",
    "        l=line.strip()\n",
    "        jdata=eval(l)\n",
    "        edge_loss_list.append(jdata['loss'])\n",
    "        edge_list.append([str(jdata['srcmsg']),str(jdata['dstmsg'])])\n",
    "    df_list_5_14.append(pd.DataFrame(edge_loss_list))\n",
    "    count,loss_avg,node_set,edge_set=cal_anomaly_loss(edge_loss_list,edge_list,\"graph_5_14/\")\n",
    "\n",
    "    current_tw['name']=f_path\n",
    "    current_tw['loss']=loss_avg\n",
    "    current_tw['index']=index_count\n",
    "    current_tw['nodeset']=node_set\n",
    "\n",
    "    added_que_flag=False\n",
    "    for hq in history_list_5_14:\n",
    "        for his_tw in hq:\n",
    "\n",
    "            if cal_set_rel(current_tw['nodeset'],his_tw['nodeset'],file_list)!=0 and current_tw['name']!=his_tw['name']:\n",
    "                print(\"history queue:\",his_tw['name'])\n",
    "\n",
    "                hq.append(copy.deepcopy(current_tw))\n",
    "                added_que_flag=True\n",
    "                break\n",
    "            if added_que_flag:\n",
    "                break\n",
    "    if added_que_flag is False:\n",
    "        temp_hq=[copy.deepcopy(current_tw)]\n",
    "        history_list_5_14.append(temp_hq)\n",
    "    index_count+=1\n",
    "    loss_list_5_14.append(loss_avg)\n",
    "    print( f_path,\"  \",loss_avg,\" count:\",count,\" percentage:\",count/len(edge_list),\" node count:\",len(node_set),\" edge count:\",len(edge_set))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['graph_5_14/2019-05-14 09:17:20.971655668~2019-05-14 09:32:31.497798481.txt']\n",
      "12.262087378474261\n"
     ]
    }
   ],
   "source": [
    "name_list=[]\n",
    "for hl in history_list_5_14:\n",
    "    loss_count=0\n",
    "    for hq in hl:\n",
    "        if loss_count==0:\n",
    "            loss_count=(loss_count+1)*(hq['loss']+1)\n",
    "        else:\n",
    "            loss_count=(loss_count)*(hq['loss']+1)\n",
    "#     name_list=[]\n",
    "    if loss_count>12:\n",
    "        name_list=[]\n",
    "        for i in hl:\n",
    "            name_list.append(i['name']) \n",
    "        print(name_list)\n",
    "        for i in name_list:\n",
    "            pred_label[i]=1\n",
    "        print(loss_count)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 5-15"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "index_count: 0\n",
      "thr: 0.945681092119721\n",
      "graph_5_15/2019-05-15 00:00:01.490408727~2019-05-15 00:16:14.833595653.txt    2.872670983056299  count: 4456  percentage: 0.025153540462427744  node count: 325  edge count: 577\n",
      "index_count: 1\n",
      "thr: 1.1010981697045046\n",
      "graph_5_15/2019-05-15 00:16:14.833595653~2019-05-15 00:32:01.492056162.txt    4.241743965137408  count: 2484  percentage: 0.017836626838235295  node count: 236  edge count: 269\n",
      "index_count: 2\n",
      "thr: 1.8056916453586969\n",
      "graph_5_15/2019-05-15 00:32:01.492056162~2019-05-15 00:47:15.554515213.txt    5.274244637287336  count: 1204  percentage: 0.032660590277777776  node count: 46  edge count: 53\n",
      "index_count: 3\n",
      "thr: 2.1217718487990944\n",
      "graph_5_15/2019-05-15 00:47:15.554515213~2019-05-15 01:04:31.491761640.txt    5.413923238846193  count: 1245  percentage: 0.04503038194444445  node count: 52  edge count: 61\n",
      "index_count: 4\n",
      "thr: 1.1083799707183994\n",
      "graph_5_15/2019-05-15 01:04:31.491761640~2019-05-15 01:20:01.492131631.txt    4.2004548255699286  count: 1889  percentage: 0.020051375679347828  node count: 74  edge count: 90\n",
      "index_count: 5\n",
      "thr: 1.2123885127074632\n",
      "graph_5_15/2019-05-15 01:20:01.492131631~2019-05-15 01:36:01.495126517.txt    4.47606157737594  count: 1631  percentage: 0.017896330758426966  node count: 77  edge count: 97\n",
      "index_count: 6\n",
      "thr: 1.4240883418007881\n",
      "graph_5_15/2019-05-15 01:36:01.495126517~2019-05-15 01:51:02.896532154.txt    4.518939656808628  count: 1646  percentage: 0.02363855698529412  node count: 60  edge count: 69\n",
      "index_count: 7\n",
      "thr: 1.0031628859654471\n",
      "graph_5_15/2019-05-15 01:51:02.896532154~2019-05-15 02:07:19.144870551.txt    4.117929255466881  count: 2045  percentage: 0.013138620476973685  node count: 81  edge count: 101\n",
      "index_count: 8\n",
      "thr: 1.6536140094440328\n",
      "graph_5_15/2019-05-15 02:07:19.144870551~2019-05-15 02:23:18.291403804.txt    4.911740046520297  count: 1495  percentage: 0.030415852864583332  node count: 56  edge count: 67\n",
      "index_count: 9\n",
      "thr: 1.477546347463332\n",
      "graph_5_15/2019-05-15 02:23:18.291403804~2019-05-15 02:39:26.758938680.txt    4.946174976998083  count: 1563  percentage: 0.022781599813432835  node count: 60  edge count: 72\n",
      "index_count: 10\n",
      "thr: 0.8453200664218685\n",
      "graph_5_15/2019-05-15 02:39:26.758938680~2019-05-15 02:54:29.939561154.txt    3.8823287478448676  count: 1667  percentage: 0.011150203339041096  node count: 74  edge count: 92\n",
      "index_count: 11\n",
      "thr: 0.8584496224117248\n",
      "graph_5_15/2019-05-15 02:54:29.939561154~2019-05-15 03:09:30.148005357.txt    3.8221410851246658  count: 1871  percentage: 0.011564230617088608  node count: 69  edge count: 93\n",
      "index_count: 12\n",
      "thr: 0.8597484400155724\n",
      "graph_5_15/2019-05-15 03:09:30.148005357~2019-05-15 03:25:02.394441209.txt    3.3522183601763698  count: 2422  percentage: 0.013831779970760233  node count: 88  edge count: 108\n",
      "index_count: 13\n",
      "thr: 1.3017947919228203\n",
      "graph_5_15/2019-05-15 03:25:02.394441209~2019-05-15 03:41:44.920119418.txt    4.661277021796017  count: 1770  percentage: 0.019867995689655173  node count: 67  edge count: 84\n",
      "index_count: 14\n",
      "thr: 0.9213808372144583\n",
      "graph_5_15/2019-05-15 03:41:44.920119418~2019-05-15 03:58:07.697665053.txt    3.1549534198312683  count: 3242  percentage: 0.01873382026627219  node count: 119  edge count: 148\n",
      "index_count: 15\n",
      "thr: 1.100098623970432\n",
      "graph_5_15/2019-05-15 03:58:07.697665053~2019-05-15 04:14:56.274252703.txt    4.284808423586645  count: 2013  percentage: 0.016801883012820512  node count: 71  edge count: 83\n",
      "index_count: 16\n",
      "thr: 1.1735872452055298\n",
      "graph_5_15/2019-05-15 04:14:56.274252703~2019-05-15 04:31:01.490574676.txt    4.468432586578077  count: 1381  percentage: 0.018224767736486486  node count: 63  edge count: 73\n",
      "index_count: 17\n",
      "thr: 1.6200381595960405\n",
      "graph_5_15/2019-05-15 04:31:01.490574676~2019-05-15 04:46:31.301354716.txt    4.865030710119754  count: 1280  percentage: 0.029069767441860465  node count: 55  edge count: 66\n",
      "index_count: 18\n",
      "thr: 1.9794138996401358\n",
      "graph_5_15/2019-05-15 04:46:31.301354716~2019-05-15 05:01:36.395374506.txt    5.036603730390183  count: 1007  percentage: 0.042756453804347824  node count: 45  edge count: 51\n",
      "index_count: 19\n",
      "thr: 1.319457780557249\n",
      "graph_5_15/2019-05-15 05:01:36.395374506~2019-05-15 05:17:01.503229576.txt    4.4227440188340355  count: 1666  percentage: 0.02392578125  node count: 58  edge count: 67\n",
      "index_count: 20\n",
      "thr: 2.119808220946803\n",
      "graph_5_15/2019-05-15 05:17:01.503229576~2019-05-15 05:32:11.337521289.txt    5.242078079963663  count: 1049  percentage: 0.046564275568181816  node count: 49  edge count: 54\n",
      "index_count: 21\n",
      "thr: 1.679402648688269\n",
      "graph_5_15/2019-05-15 05:32:11.337521289~2019-05-15 05:48:01.503688497.txt    5.062880347105447  count: 1335  percentage: 0.028341542119565216  node count: 51  edge count: 60\n",
      "index_count: 22\n",
      "thr: 1.922330151023874\n",
      "graph_5_15/2019-05-15 05:48:01.503688497~2019-05-15 06:05:01.495772298.txt    5.39177715263249  count: 1296  percentage: 0.03616071428571429  node count: 43  edge count: 52\n",
      "index_count: 23\n",
      "thr: 1.5634351702245295\n",
      "graph_5_15/2019-05-15 06:05:01.495772298~2019-05-15 06:20:51.005863855.txt    5.075873504049137  count: 1794  percentage: 0.025027901785714287  node count: 68  edge count: 81\n",
      "index_count: 24\n",
      "thr: 1.9510134015343619\n",
      "graph_5_15/2019-05-15 06:20:51.005863855~2019-05-15 06:36:01.491983616.txt    5.590569725458056  count: 1007  percentage: 0.03391029094827586  node count: 50  edge count: 55\n",
      "index_count: 25\n",
      "thr: 1.133893060690158\n",
      "graph_5_15/2019-05-15 06:36:01.491983616~2019-05-15 06:53:31.493116975.txt    4.244095755808017  count: 1751  percentage: 0.018999565972222222  node count: 69  edge count: 80\n",
      "index_count: 26\n",
      "thr: 1.6257357622614346\n",
      "graph_5_15/2019-05-15 06:53:31.493116975~2019-05-15 07:09:55.168118324.txt    4.257884927243593  count: 1992  percentage: 0.03536931818181818  node count: 703  edge count: 711\n",
      "index_count: 27\n",
      "thr: 2.813202121331055\n",
      "graph_5_15/2019-05-15 07:09:55.168118324~2019-05-15 07:27:01.254806380.txt    5.913687727978973  count: 976  percentage: 0.06808035714285714  node count: 38  edge count: 43\n",
      "index_count: 28\n",
      "thr: 0.8331968176788251\n",
      "graph_5_15/2019-05-15 07:27:01.254806380~2019-05-15 07:42:05.122895776.txt    3.5648005453239437  count: 1853  percentage: 0.012833832003546099  node count: 90  edge count: 118\n",
      "index_count: 29\n",
      "thr: 2.147800453871211\n",
      "graph_5_15/2019-05-15 07:42:05.122895776~2019-05-15 07:57:29.435273604.txt    4.4086198184983845  count: 15890  percentage: 0.06412222365702479  node count: 275  edge count: 321\n",
      "index_count: 30\n",
      "thr: 1.1555657322232409\n",
      "graph_5_15/2019-05-15 07:57:29.435273604~2019-05-15 08:12:40.385079790.txt    4.467846769674385  count: 1737  percentage: 0.01663028492647059  node count: 79  edge count: 101\n",
      "index_count: 31\n",
      "thr: 0.880845828714572\n",
      "graph_5_15/2019-05-15 08:12:40.385079790~2019-05-15 08:28:58.370499520.txt    3.0927909622859278  count: 3096  percentage: 0.01591282894736842  node count: 88  edge count: 112\n",
      "index_count: 32\n",
      "thr: 1.028738835202042\n",
      "graph_5_15/2019-05-15 08:28:58.370499520~2019-05-15 08:46:17.912177800.txt    4.983848666148356  count: 1651  percentage: 0.012122591635338346  node count: 63  edge count: 76\n",
      "index_count: 33\n",
      "thr: 0.6155950130232596\n",
      "graph_5_15/2019-05-15 08:46:17.912177800~2019-05-15 09:01:36.712206897.txt    1.029004970865521  count: 25145  percentage: 0.056449802442528736  node count: 145  edge count: 184\n",
      "index_count: 34\n",
      "thr: 0.7378044687901514\n",
      "graph_5_15/2019-05-15 09:01:36.712206897~2019-05-15 09:18:20.052280739.txt    1.657765522098651  count: 11312  percentage: 0.029537098930481284  node count: 96  edge count: 135\n",
      "index_count: 35\n",
      "thr: 1.0656119625585718\n",
      "graph_5_15/2019-05-15 09:18:20.052280739~2019-05-15 09:33:20.409598023.txt    3.6205703404678733  count: 5223  percentage: 0.018752154181985295  node count: 619  edge count: 658\n",
      "index_count: 36\n",
      "thr: 1.7961948040837705\n",
      "graph_5_15/2019-05-15 09:33:20.409598023~2019-05-15 09:48:20.851554754.txt    5.788713605687169  count: 1616  percentage: 0.026747881355932205  node count: 419  edge count: 426\n",
      "index_count: 37\n",
      "thr: 0.7472388453275733\n",
      "graph_5_15/2019-05-15 09:48:20.851554754~2019-05-15 10:04:07.712341272.txt    1.7527844500086573  count: 9482  percentage: 0.027395756286982247  node count: 99  edge count: 132\n",
      "index_count: 38\n",
      "thr: 0.7022227057384569\n",
      "graph_5_15/2019-05-15 10:04:07.712341272~2019-05-15 10:19:12.055930735.txt    1.28707670859545  count: 17282  percentage: 0.04429646489501313  node count: 113  edge count: 143\n",
      "index_count: 39\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "thr: 1.116515977882949\n",
      "graph_5_15/2019-05-15 10:19:12.055930735~2019-05-15 10:34:12.998931412.txt    4.533200002741069  count: 2048  percentage: 0.014492753623188406  node count: 83  edge count: 100\n",
      "index_count: 40\n",
      "thr: 1.3770716854480338\n",
      "graph_5_15/2019-05-15 10:34:12.998931412~2019-05-15 10:52:01.493441398.txt    4.73800199160409  count: 1743  percentage: 0.020263671875  node count: 70  edge count: 84\n",
      "index_count: 41\n",
      "thr: 1.0210062882328663\n",
      "graph_5_15/2019-05-15 10:52:01.493441398~2019-05-15 11:07:01.494486145.txt    5.034915268764386  count: 1563  percentage: 0.01106063179347826  node count: 74  edge count: 96\n",
      "index_count: 42\n",
      "thr: 1.0453656167294556\n",
      "graph_5_15/2019-05-15 11:07:01.494486145~2019-05-15 11:22:08.001455967.txt    3.694019190344412  count: 2776  percentage: 0.017157832278481014  node count: 88  edge count: 109\n",
      "index_count: 43\n",
      "thr: 1.356331025799893\n",
      "graph_5_15/2019-05-15 11:22:08.001455967~2019-05-15 11:38:31.497341568.txt    4.5939060402837795  count: 1708  percentage: 0.02166193181818182  node count: 71  edge count: 83\n",
      "index_count: 44\n",
      "thr: 0.7392389957963641\n",
      "graph_5_15/2019-05-15 11:38:31.497341568~2019-05-15 11:54:52.383589579.txt    1.799350726974879  count: 9526  percentage: 0.027604553041543026  node count: 91  edge count: 113\n",
      "index_count: 45\n",
      "thr: 0.3678693030065403\n",
      "graph_5_15/2019-05-15 11:54:52.383589579~2019-05-15 13:27:01.496190252.txt    1.0572820889272652  count: 2271  percentage: 0.020161576704545454  node count: 59  edge count: 71\n",
      "index_count: 46\n",
      "thr: 2.703709590263338\n",
      "graph_5_15/2019-05-15 13:27:01.496190252~2019-05-15 13:42:24.177751369.txt    6.641550741313225  count: 27585  percentage: 0.04827683971774194  node count: 1658  edge count: 2423\n",
      "index_count: 47\n",
      "thr: 3.7025304485428863\n",
      "graph_5_15/2019-05-15 13:42:24.177751369~2019-05-15 13:58:15.520482252.txt    9.905020742213301  count: 5917  percentage: 0.042802372685185185  node count: 228  edge count: 269\n",
      "index_count: 48\n",
      "thr: 15.317113294451019\n",
      "graph_5_15/2019-05-15 13:58:15.520482252~2019-05-15 14:13:37.257086895.txt    15.466566590529222  count: 325  percentage: 0.0010338202361563518  node count: 4  edge count: 3\n",
      "index_count: 49\n",
      "thr: 1.151644016354555\n",
      "graph_5_15/2019-05-15 14:13:37.257086895~2019-05-15 14:29:18.996669142.txt    4.552575053707246  count: 2883  percentage: 0.012855843321917809  node count: 155  edge count: 184\n",
      "index_count: 50\n",
      "thr: 1.1161253956799913\n",
      "graph_5_15/2019-05-15 14:29:18.996669142~2019-05-15 14:44:51.773840192.txt    4.442778381840277  count: 1148  percentage: 0.012054771505376344  node count: 95  edge count: 118\n",
      "index_count: 51\n",
      "thr: 9.367514361702359\n",
      "graph_5_15/2019-05-15 14:44:51.773840192~2019-05-15 15:00:26.765466538.txt    11.247159616309874  count: 62345  percentage: 0.2063857256355932  node count: 202  edge count: 219\n",
      "index_count: 52\n",
      "thr: 2.2455788957245337\n",
      "graph_5_15/2019-05-15 15:00:26.765466538~2019-05-15 15:17:03.203703087.txt    5.910884570225841  count: 2245  percentage: 0.039861505681818184  node count: 978  edge count: 988\n",
      "index_count: 53\n",
      "thr: 0.8084541673202799\n",
      "graph_5_15/2019-05-15 15:17:03.203703087~2019-05-15 15:34:25.452570637.txt    3.518693755464356  count: 2118  percentage: 0.009233747209821428  node count: 93  edge count: 119\n",
      "index_count: 54\n",
      "thr: 1.3598701647981497\n",
      "graph_5_15/2019-05-15 15:34:25.452570637~2019-05-15 15:49:43.447021039.txt    5.329456750947858  count: 1746  percentage: 0.016238839285714287  node count: 59  edge count: 68\n",
      "index_count: 55\n",
      "thr: 1.0104829330209066\n",
      "graph_5_15/2019-05-15 15:49:43.447021039~2019-05-15 16:05:41.064452218.txt    4.023669249803117  count: 1133  percentage: 0.01286564316860465  node count: 79  edge count: 95\n",
      "index_count: 56\n",
      "thr: 1.3000112300835247\n",
      "graph_5_15/2019-05-15 16:05:41.064452218~2019-05-15 16:22:39.979479840.txt    5.506782718485208  count: 556  percentage: 0.01262718023255814  node count: 67  edge count: 74\n",
      "index_count: 57\n",
      "thr: 0.904425660615334\n",
      "graph_5_15/2019-05-15 16:22:39.979479840~2019-05-15 16:38:00.022566187.txt    3.458445117085964  count: 1716  percentage: 0.011477953767123288  node count: 77  edge count: 96\n",
      "index_count: 58\n",
      "thr: 1.080316426747338\n",
      "graph_5_15/2019-05-15 16:38:00.022566187~2019-05-15 16:54:31.494483643.txt    3.7194978318905636  count: 2718  percentage: 0.01830549568965517  node count: 104  edge count: 123\n",
      "index_count: 59\n",
      "thr: 0.6208952049956693\n",
      "graph_5_15/2019-05-15 16:54:31.494483643~2019-05-15 17:10:01.626108726.txt    1.1818040329052653  count: 8512  percentage: 0.03744369369369369  node count: 80  edge count: 99\n",
      "index_count: 60\n",
      "thr: 1.144236487260263\n",
      "graph_5_15/2019-05-15 17:10:01.626108726~2019-05-15 17:25:14.590228152.txt    4.595926803730373  count: 957  percentage: 0.011981670673076924  node count: 78  edge count: 92\n",
      "index_count: 61\n",
      "thr: 0.8570309754056273\n",
      "graph_5_15/2019-05-15 17:25:14.590228152~2019-05-15 17:43:54.631759423.txt    3.582717638117511  count: 2460  percentage: 0.010724748883928572  node count: 87  edge count: 107\n",
      "index_count: 62\n",
      "thr: 1.2349663882742452\n",
      "graph_5_15/2019-05-15 17:43:54.631759423~2019-05-15 18:00:21.533587327.txt    4.99860761186938  count: 671  percentage: 0.011106329449152543  node count: 62  edge count: 70\n",
      "index_count: 63\n",
      "thr: 0.5365865129445927\n",
      "graph_5_15/2019-05-15 18:00:21.533587327~2019-05-15 18:16:33.957928738.txt    1.1178859331061948  count: 13566  percentage: 0.03639573317307692  node count: 101  edge count: 121\n",
      "index_count: 64\n",
      "thr: 0.8729541616830677\n",
      "graph_5_15/2019-05-15 18:16:33.957928738~2019-05-15 18:32:44.229252473.txt    3.497438193836045  count: 2963  percentage: 0.012975581558295965  node count: 80  edge count: 98\n",
      "index_count: 65\n",
      "thr: 1.3440031607279295\n",
      "graph_5_15/2019-05-15 18:32:44.229252473~2019-05-15 18:50:02.896672585.txt    5.534047100387636  count: 488  percentage: 0.013616071428571429  node count: 54  edge count: 60\n",
      "index_count: 66\n",
      "thr: 0.9587554091113772\n",
      "graph_5_15/2019-05-15 18:50:02.896672585~2019-05-15 19:05:15.589701783.txt    3.9386413422882134  count: 846  percentage: 0.011802455357142857  node count: 80  edge count: 91\n",
      "index_count: 67\n",
      "thr: 0.9555466344327963\n",
      "graph_5_15/2019-05-15 19:05:15.589701783~2019-05-15 19:21:31.509532475.txt    3.6038202551466907  count: 1608  percentage: 0.012079326923076924  node count: 82  edge count: 99\n",
      "index_count: 68\n",
      "thr: 0.6508760288269272\n",
      "graph_5_15/2019-05-15 19:21:31.509532475~2019-05-15 19:37:24.849404892.txt    1.4091580368200318  count: 4867  percentage: 0.030467497996794872  node count: 77  edge count: 90\n",
      "index_count: 69\n",
      "thr: 0.8878266033870724\n",
      "graph_5_15/2019-05-15 19:37:24.849404892~2019-05-15 19:56:19.975334466.txt    2.8781119005729385  count: 3917  percentage: 0.01981966483160622  node count: 85  edge count: 108\n",
      "index_count: 70\n",
      "thr: 1.0386016700530711\n",
      "graph_5_15/2019-05-15 19:56:19.975334466~2019-05-15 20:12:58.479720072.txt    3.486795524523176  count: 2900  percentage: 0.015560611263736264  node count: 102  edge count: 124\n",
      "index_count: 71\n",
      "thr: 1.0685031130861047\n",
      "graph_5_15/2019-05-15 20:12:58.479720072~2019-05-15 20:28:31.496181001.txt    4.496421564873506  count: 1977  percentage: 0.014092438412408759  node count: 79  edge count: 91\n",
      "index_count: 72\n",
      "thr: 0.7543929789245893\n",
      "graph_5_15/2019-05-15 20:28:31.496181001~2019-05-15 20:45:02.944896082.txt    1.6200210608701393  count: 3505  percentage: 0.0302907217920354  node count: 78  edge count: 96\n",
      "index_count: 73\n",
      "thr: 0.7346672387771268\n",
      "graph_5_15/2019-05-15 20:45:02.944896082~2019-05-15 21:00:14.411230352.txt    1.541632944294288  count: 10946  percentage: 0.035631510416666665  node count: 99  edge count: 124\n",
      "index_count: 74\n",
      "thr: 0.8049171406238331\n",
      "graph_5_15/2019-05-15 21:00:14.411230352~2019-05-15 21:16:04.951215086.txt    2.6834422245613743  count: 3754  percentage: 0.017883003048780488  node count: 93  edge count: 109\n",
      "index_count: 75\n",
      "thr: 0.9840134298642742\n",
      "graph_5_15/2019-05-15 21:16:04.951215086~2019-05-15 21:31:25.960086974.txt    3.566122028934126  count: 963  percentage: 0.01288259845890411  node count: 73  edge count: 84\n",
      "index_count: 76\n",
      "thr: 1.1341789204752812\n",
      "graph_5_15/2019-05-15 21:31:25.960086974~2019-05-15 21:47:41.306583947.txt    4.461605528641862  count: 855  percentage: 0.011760013204225352  node count: 68  edge count: 79\n",
      "index_count: 77\n",
      "thr: 1.2375815611594485\n",
      "graph_5_15/2019-05-15 21:47:41.306583947~2019-05-15 22:03:31.522168702.txt    5.507561126161129  count: 470  percentage: 0.009977921195652174  node count: 57  edge count: 70\n",
      "index_count: 78\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "thr: 1.1740526947930534\n",
      "graph_5_15/2019-05-15 22:03:31.522168702~2019-05-15 22:19:16.263929035.txt    3.595257699400231  count: 3335  percentage: 0.026264805947580645  node count: 227  edge count: 242\n",
      "index_count: 79\n",
      "thr: 1.0338101199110594\n",
      "graph_5_15/2019-05-15 22:19:16.263929035~2019-05-15 22:37:52.734006062.txt    4.447169624058427  count: 1486  percentage: 0.013953575721153846  node count: 71  edge count: 79\n",
      "index_count: 80\n",
      "thr: 1.166173984619087\n",
      "graph_5_15/2019-05-15 22:37:52.734006062~2019-05-15 22:55:31.494815444.txt    4.254370241505759  count: 980  percentage: 0.013870018115942028  node count: 68  edge count: 79\n",
      "index_count: 81\n",
      "thr: 0.7602195863099896\n",
      "graph_5_15/2019-05-15 22:55:31.494815444~2019-05-15 23:11:23.284826570.txt    1.746192710824715  count: 3225  percentage: 0.02460479736328125  node count: 85  edge count: 103\n",
      "index_count: 82\n",
      "thr: 1.2237977533852455\n",
      "graph_5_15/2019-05-15 23:11:23.284826570~2019-05-15 23:29:31.512587396.txt    4.992516812191091  count: 2816  percentage: 0.01676829268292683  node count: 73  edge count: 91\n",
      "index_count: 83\n",
      "thr: 1.6389899764713445\n",
      "graph_5_15/2019-05-15 23:29:31.512587396~2019-05-15 23:46:09.097590467.txt    6.507651203189078  count: 341  percentage: 0.01513671875  node count: 44  edge count: 51\n"
     ]
    }
   ],
   "source": [
    "# 5-15 \n",
    "\n",
    "# node_IDF=torch.load(\"node_IDF_5_15\")\n",
    "# node_IDF=torch.load(\"node_IDF_5_9\")\n",
    "y_data_5_15=[]\n",
    "df_list_5_15=[]\n",
    "# node_set_list=[]\n",
    "history_list_5_15=[]\n",
    "tw_que=[]\n",
    "his_tw={}\n",
    "current_tw={}\n",
    "loss_list_5_15=[]\n",
    "\n",
    "\n",
    "\n",
    "file_path_list=[]\n",
    "file_path=\"graph_5_15/\"\n",
    "file_l=os.listdir(\"graph_5_15/\")\n",
    "for i in file_l:\n",
    "    file_path_list.append(file_path+i)\n",
    "\n",
    "index_count=0\n",
    "for f_path in sorted(file_path_list):\n",
    "    f=open(f_path)\n",
    "    edge_loss_list=[]\n",
    "    edge_list=[]\n",
    "    print('index_count:',index_count)\n",
    "    \n",
    "    for line in f:\n",
    "        l=line.strip()\n",
    "        jdata=eval(l)\n",
    "        edge_loss_list.append(jdata['loss'])\n",
    "        edge_list.append([str(jdata['srcmsg']),str(jdata['dstmsg'])])\n",
    "    df_list_5_15.append(pd.DataFrame(edge_loss_list))\n",
    "    count,loss_avg,node_set,edge_set=cal_anomaly_loss(edge_loss_list,edge_list,\"graph_5_15/\")\n",
    "\n",
    "    current_tw['name']=f_path\n",
    "    current_tw['loss']=loss_avg\n",
    "    current_tw['index']=index_count\n",
    "    current_tw['nodeset']=node_set\n",
    "\n",
    "    added_que_flag=False\n",
    "    for hq in history_list_5_15:\n",
    "        for his_tw in hq:\n",
    "\n",
    "            if cal_set_rel(current_tw['nodeset'],his_tw['nodeset'],file_list)!=0 and current_tw['name']!=his_tw['name']:\n",
    "                print(\"history queue:\",his_tw['name'])\n",
    "                hq.append(copy.deepcopy(current_tw))\n",
    "                added_que_flag=True\n",
    "                break\n",
    "            if added_que_flag:\n",
    "                break\n",
    "    if added_que_flag is False:\n",
    "        temp_hq=[copy.deepcopy(current_tw)]\n",
    "        history_list_5_15.append(temp_hq)\n",
    "    index_count+=1\n",
    "    loss_list_5_15.append(loss_avg)\n",
    "    print( f_path,\"  \",loss_avg,\" count:\",count,\" percentage:\",count/len(edge_list),\" node count:\",len(node_set),\" edge count:\",len(edge_set))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['graph_5_15/2019-05-15 13:58:15.520482252~2019-05-15 14:13:37.257086895.txt']\n",
      "16.466566590529222\n",
      "['graph_5_15/2019-05-15 14:44:51.773840192~2019-05-15 15:00:26.765466538.txt']\n",
      "12.247159616309874\n"
     ]
    }
   ],
   "source": [
    "name_list=[]\n",
    "for hl in history_list_5_15:\n",
    "    loss_count=0\n",
    "    for hq in hl:\n",
    "        if loss_count==0:\n",
    "            loss_count=(loss_count+1)*(hq['loss']+1)\n",
    "        else:\n",
    "            loss_count=(loss_count)*(hq['loss']+1)\n",
    "#     name_list=[]\n",
    "    if loss_count>12:\n",
    "        name_list=[]\n",
    "        for i in hl:\n",
    "            name_list.append(i['name']) \n",
    "        print(name_list)\n",
    "        for i in name_list:\n",
    "            pred_label[i]=1\n",
    "        print(loss_count)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.metrics import average_precision_score, roc_auc_score\n",
    "\n",
    "# from sklearn.metrics import plot_roc_curve,roc_curve,auc,roc_auc_score\n",
    "import torch\n",
    "from sklearn import preprocessing\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "from sklearn.preprocessing import MinMaxScaler\n",
    "from sklearn.metrics import confusion_matrix\n",
    "\n",
    "def plot_thr():\n",
    "    np.seterr(invalid='ignore')\n",
    "    step=0.01\n",
    "    thr_list=torch.arange(-5,5,step)\n",
    "    \n",
    "    \n",
    "\n",
    "    precision_list=[]\n",
    "    recall_list=[]\n",
    "    fscore_list=[]\n",
    "    accuracy_list=[]\n",
    "    auc_val_list=[]\n",
    "    for thr in thr_list:\n",
    "        threshold=thr\n",
    "        y_prediction=[]\n",
    "        for i in y_test_scores:\n",
    "            if i >threshold:\n",
    "                y_prediction.append(1)\n",
    "            else:\n",
    "                y_prediction.append(0)\n",
    "        precision,recall,fscore,accuracy,auc_val=classifier_evaluation(y_test, y_prediction)   \n",
    "        precision_list.append(float(precision))\n",
    "        recall_list.append(float(recall))\n",
    "        fscore_list.append(float(fscore))\n",
    "        accuracy_list.append(float(accuracy))\n",
    "        auc_val_list.append(float(auc_val))\n",
    "\n",
    "    max_fscore=max(fscore_list)\n",
    "    max_fscore_index=fscore_list.index(max_fscore)\n",
    "    print(max_fscore_index)\n",
    "    print(\"max threshold:\",thr_list[max_fscore_index])\n",
    "    print('precision:',precision_list[max_fscore_index])\n",
    "    print('recall:',recall_list[max_fscore_index])\n",
    "    print('fscore:',fscore_list[max_fscore_index])\n",
    "    print('accuracy:',accuracy_list[max_fscore_index])    \n",
    "    print('auc:',auc_val_list[max_fscore_index])\n",
    "\n",
    "    plt.plot(thr_list,precision_list,color='red',label='precision',linewidth=2.0,linestyle='-')\n",
    "    plt.plot(thr_list,recall_list,color='orange',label='recall',linewidth=2.0,linestyle='solid')\n",
    "    plt.plot(thr_list,fscore_list,color='y',label='F-score',linewidth=2.0,linestyle='dashed')\n",
    "    plt.plot(thr_list,accuracy_list,color='g',label='accuracy',linewidth=2.0,linestyle='dashdot')\n",
    "    plt.plot(thr_list,auc_val_list,color='b',label='auc_val',linewidth=2.0,linestyle='dotted')\n",
    "\n",
    "\n",
    "    plt.xlabel(\"Threshold\", fontdict={'size': 16})\n",
    "    plt.ylabel(\"Rate\", fontdict={'size': 16})\n",
    "    plt.title(\"Different evaluation Indicators by varying threshold value\", fontdict={'size': 12})\n",
    "    plt.legend(loc='best', fontsize=12, markerscale=0.5)\n",
    "    plt.show()\n",
    "\n",
    "def classifier_evaluation(y_test, y_test_pred):\n",
    "    # groundtruth, pred_value\n",
    "    tn, fp, fn, tp =confusion_matrix(y_test, y_test_pred).ravel()\n",
    "#     tn+=100\n",
    "#     print(clf_name,\" : \")\n",
    "    print('tn:',tn)\n",
    "    print('fp:',fp)\n",
    "    print('fn:',fn)\n",
    "    print('tp:',tp)\n",
    "    precision=tp/(tp+fp)\n",
    "    recall=tp/(tp+fn)\n",
    "    accuracy=(tp+tn)/(tp+tn+fp+fn)\n",
    "    fscore=2*(precision*recall)/(precision+recall)    \n",
    "    auc_val=roc_auc_score(y_test, y_test_pred)\n",
    "    print(\"precision:\",precision)\n",
    "    print(\"recall:\",recall)\n",
    "    print(\"fscore:\",fscore)\n",
    "    print(\"accuracy:\",accuracy)\n",
    "    print(\"auc_val:\",auc_val)\n",
    "    return precision,recall,fscore,accuracy,auc_val\n",
    "\n",
    "def minmax(data):\n",
    "    min_val=min(data)\n",
    "    max_val=max(data)\n",
    "    ans=[]\n",
    "    for i in data:\n",
    "        ans.append((i-min_val)/(max_val-min_val))\n",
    "    return ans\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [],
   "source": [
    "y=[]\n",
    "y_pred=[]\n",
    "for i in labels:\n",
    "    y.append(labels[i])\n",
    "    y_pred.append(pred_label[i])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn: 173\n",
      "fp: 1\n",
      "fn: 0\n",
      "tp: 2\n",
      "precision: 0.6666666666666666\n",
      "recall: 1.0\n",
      "fscore: 0.8\n",
      "accuracy: 0.9943181818181818\n",
      "auc_val: 0.9971264367816092\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(0.6666666666666666, 1.0, 0.8, 0.9943181818181818, 0.9971264367816092)"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "classifier_evaluation(y,y_pred)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Count attack edge numbers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def keyword_hit(line):\n",
    "    attack_nodes=[\n",
    "#             'sshd',\n",
    "            'sshdlog',\n",
    "        'shm',\n",
    "#          'python',\n",
    "#             'firefox',\n",
    "        '189.141.204.211',\n",
    "        '208.203.20.42',\n",
    "       \n",
    "#         '',\n",
    "#         '',\n",
    "#         '',\n",
    "        ]\n",
    "    flag=False\n",
    "    for i in attack_nodes:\n",
    "        if i in line:\n",
    "            flag=True\n",
    "            break\n",
    "    return flag\n",
    "\n",
    "\n",
    "\n",
    "files=[    \n",
    "    'graph_5_15/2019-05-15 13:58:15.520482252~2019-05-15 14:13:37.257086895.txt',\n",
    "    'graph_5_15/2019-05-15 14:44:51.773840192~2019-05-15 15:00:26.765466538.txt',]\n",
    "\n",
    "attack_edge_count=0\n",
    "for fpath in tqdm(files):\n",
    "    f=open(fpath)\n",
    "    for line in f:\n",
    "        if keyword_hit(line):\n",
    "            attack_edge_count+=1\n",
    "print(attack_edge_count)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Visualization"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 50%|██████████████████████████████████████████████                                              | 1/2 [00:02<00:02,  2.95s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7.4023464798260585\n",
      "5.276511209749973\n",
      "thr: 15.317113294451019\n",
      "2.5436744946904866\n",
      "4.549226578007914\n",
      "thr: 9.367514361702359\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|████████████████████████████████████████████████████████████████████████████████████████████| 2/2 [00:06<00:00,  3.25s/it]\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "\n",
    "from graphviz import Digraph\n",
    "import networkx as nx\n",
    "import datetime\n",
    "import community.community_louvain as community_louvain\n",
    "from tqdm import tqdm\n",
    "\n",
    "\n",
    "\n",
    "# Some common path abstraction for visualization\n",
    "replace_dic = {\n",
    "        '/run/shm/':'/run/shm/*',\n",
    "        #     '/home/admin/.cache/mozilla/firefox/pe11scpa.default/cache2/entries/':'/home/admin/.cache/mozilla/firefox/pe11scpa.default/cache2/entries/*',\n",
    "        '/home/admin/.cache/mozilla/firefox/':'/home/admin/.cache/mozilla/firefox/*',\n",
    "        '/home/admin/.mozilla/firefox':'/home/admin/.mozilla/firefox*',\n",
    "        '/data/replay_logdb/':'/data/replay_logdb/*',\n",
    "        '/home/admin/.local/share/applications/':'/home/admin/.local/share/applications/*',\n",
    "        '/usr/share/applications/':'/usr/share/applications/*',\n",
    "        '/lib/x86_64-linux-gnu/':'/lib/x86_64-linux-gnu/*',\n",
    "        '/proc/':'/proc/*',\n",
    "        '/stat':'*/stat',\n",
    "        '/etc/bash_completion.d/':'/etc/bash_completion.d/*',\n",
    "        '/usr/bin/python2.7':'/usr/bin/python2.7/*',\n",
    "        '/usr/lib/python2.7':'/usr/lib/python2.7/*',\n",
    "        '/data/data/org.mozilla.fennec_firefox_dev/cache/':'/data/data/org.mozilla.fennec_firefox_dev/cache/*',\n",
    "        'UNNAMED':'UNNAMED*',\n",
    "        '/etc/fonts/':'/etc/fonts/*',\n",
    "}\n",
    "\n",
    "\n",
    "def replace_path_name(path_name):\n",
    "    for i in replace_dic:\n",
    "        if i in path_name:\n",
    "            return replace_dic[i]\n",
    "    return path_name\n",
    "\n",
    "\n",
    "# Users should manually put the detected anomalous time windows here\n",
    "attack_list = [\n",
    "        'graph_5_15/2019-05-15 13:58:15.520482252~2019-05-15 14:13:37.257086895.txt',\n",
    "        'graph_5_15/2019-05-15 14:44:51.773840192~2019-05-15 15:00:26.765466538.txt',\n",
    "]\n",
    "\n",
    "original_edges_count = 0\n",
    "graphs = []\n",
    "gg = nx.DiGraph()\n",
    "count = 0\n",
    "for path in tqdm(attack_list):\n",
    "    if \".txt\" in path:\n",
    "        line_count = 0\n",
    "        node_set = set()\n",
    "        tempg = nx.DiGraph()\n",
    "        f = open(path, \"r\")\n",
    "        edge_list = []\n",
    "        for line in f:\n",
    "            count += 1\n",
    "            l = line.strip()\n",
    "            jdata = eval(l)\n",
    "            edge_list.append(jdata)\n",
    "\n",
    "        edge_list = sorted(edge_list, key=lambda x: x['loss'], reverse=True)\n",
    "        original_edges_count += len(edge_list)\n",
    "\n",
    "        loss_list = []\n",
    "        for i in edge_list:\n",
    "            loss_list.append(i['loss'])\n",
    "        loss_mean = mean(loss_list)\n",
    "        loss_std = std(loss_list)\n",
    "        print(loss_mean)\n",
    "        print(loss_std)\n",
    "        thr = loss_mean + 1.5 * loss_std\n",
    "        print(\"thr:\", thr)\n",
    "        for e in edge_list:\n",
    "            if e['loss'] > thr:\n",
    "                tempg.add_edge(str(hashgen(replace_path_name(e['srcmsg']))),\n",
    "                               str(hashgen(replace_path_name(e['dstmsg']))))\n",
    "                gg.add_edge(str(hashgen(replace_path_name(e['srcmsg']))), str(hashgen(replace_path_name(e['dstmsg']))),\n",
    "                            loss=e['loss'], srcmsg=e['srcmsg'], dstmsg=e['dstmsg'], edge_type=e['edge_type'],\n",
    "                            time=e['time'])\n",
    "\n",
    "\n",
    "partition = community_louvain.best_partition(gg.to_undirected())\n",
    "\n",
    "# Generate the candidate subgraphs based on community discovery results\n",
    "communities = {}\n",
    "max_partition = 0\n",
    "for i in partition:\n",
    "    if partition[i] > max_partition:\n",
    "        max_partition = partition[i]\n",
    "for i in range(max_partition + 1):\n",
    "    communities[i] = nx.DiGraph()\n",
    "for e in gg.edges:\n",
    "    communities[partition[e[0]]].add_edge(e[0], e[1])\n",
    "    communities[partition[e[1]]].add_edge(e[0], e[1])\n",
    "\n",
    "\n",
    "# Define the attack nodes. They are **only be used to plot the colors of attack nodes and edges**.\n",
    "# They won't change the detection results.\n",
    "# Didn't add too much nodes for coloring. Most of the results are compared with the ground truth documentations manually\n",
    "def attack_edge_flag(msg):\n",
    "    attack_nodes = [\n",
    "        '208.203.20.42',\n",
    "        '189.141.204.211',\n",
    "        '/var/log/sshdlog',\n",
    "        '/usr/sbin/sshd',\n",
    "        '/usr/local/lib/firefox-54.0.1/firefox',\n",
    "    ]\n",
    "    flag = False\n",
    "    for i in attack_nodes:\n",
    "        if i in str(msg):\n",
    "            flag = True\n",
    "    return flag\n",
    "\n",
    "\n",
    "# Plot and render candidate subgraph\n",
    "os.system(f\"mkdir -p ./graph_visual/\")\n",
    "graph_index = 0\n",
    "for c in communities:\n",
    "    dot = Digraph(name=\"MyPicture\", comment=\"the test\", format=\"pdf\")\n",
    "    dot.graph_attr['rankdir'] = 'LR'\n",
    "\n",
    "    for e in communities[c].edges:\n",
    "        try:\n",
    "            temp_edge = gg.edges[e]\n",
    "            srcnode = e['srcnode']\n",
    "            dstnode = e['dstnode']\n",
    "        except:\n",
    "            pass\n",
    "\n",
    "        if True:\n",
    "            # source node\n",
    "            if \"'subject': '\" in temp_edge['srcmsg']:\n",
    "                src_shape = 'box'\n",
    "            elif \"'file': '\" in temp_edge['srcmsg']:\n",
    "                src_shape = 'oval'\n",
    "            elif \"'netflow': '\" in temp_edge['srcmsg']:\n",
    "                src_shape = 'diamond'\n",
    "            if attack_edge_flag(temp_edge['srcmsg']):\n",
    "                src_node_color = 'red'\n",
    "            else:\n",
    "                src_node_color = 'blue'\n",
    "            dot.node(name=str(hashgen(replace_path_name(temp_edge['srcmsg']))), label=str(\n",
    "                replace_path_name(temp_edge['srcmsg']) + str(\n",
    "                    partition[str(hashgen(replace_path_name(temp_edge['srcmsg'])))])), color=src_node_color,\n",
    "                     shape=src_shape)\n",
    "\n",
    "            # destination node\n",
    "            if \"'subject': '\" in temp_edge['dstmsg']:\n",
    "                dst_shape = 'box'\n",
    "            elif \"'file': '\" in temp_edge['dstmsg']:\n",
    "                dst_shape = 'oval'\n",
    "            elif \"'netflow': '\" in temp_edge['dstmsg']:\n",
    "                dst_shape = 'diamond'\n",
    "            if attack_edge_flag(temp_edge['dstmsg']):\n",
    "                dst_node_color = 'red'\n",
    "            else:\n",
    "                dst_node_color = 'blue'\n",
    "            dot.node(name=str(hashgen(replace_path_name(temp_edge['dstmsg']))), label=str(\n",
    "                replace_path_name(temp_edge['dstmsg']) + str(\n",
    "                    partition[str(hashgen(replace_path_name(temp_edge['dstmsg'])))])), color=dst_node_color,\n",
    "                     shape=dst_shape)\n",
    "\n",
    "            if attack_edge_flag(temp_edge['srcmsg']) and attack_edge_flag(temp_edge['dstmsg']):\n",
    "                edge_color = 'red'\n",
    "            else:\n",
    "                edge_color = 'blue'\n",
    "            dot.edge(str(hashgen(replace_path_name(temp_edge['srcmsg']))),\n",
    "                     str(hashgen(replace_path_name(temp_edge['dstmsg']))), label=temp_edge['edge_type'],\n",
    "                     color=edge_color)\n",
    "\n",
    "    dot.render(f'./graph_visual/subgraph_' + str(graph_index), view=False)\n",
    "    graph_index += 1\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.16"
  },
  "latex_envs": {
   "LaTeX_envs_menu_present": true,
   "autoclose": false,
   "autocomplete": true,
   "bibliofile": "biblio.bib",
   "cite_by": "apalike",
   "current_citInitial": 1,
   "eqLabelWithNumbers": true,
   "eqNumInitial": 1,
   "hotkeys": {
    "equation": "Ctrl-E",
    "itemize": "Ctrl-I"
   },
   "labels_anchors": false,
   "latex_user_defs": false,
   "report_style_numbering": false,
   "user_envs_cfg": false
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "225.797px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
